Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi, I am doing a game that requires an object to hit other balls around. I have already done the game and the phone application. I am using Bluetooth connection as a platform to communicate with the PC. It is also done already. In the phone application, I have created 4 arrow buttons to give a command for the object to move left, right, bottom, up via Bluetooth. However I do not know the code to test it out. Please help me T.T Have been trying it for days.


Here is my code for the xaml
XML
<?xml version="1.0" encoding="utf-8"?>
 <!-- Copyright (C) 2009 The Android Open Source Project

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 -->

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:removed="#B5DDF5"
     >

    <TextView
       android:id="@+id/textView1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Ice Showdown Button Gameplay"
       android:textColor="#0E4A6E"
       android:textSize="45dp" />

   <ListView
       android:id="@+id/in"
       android:layout_width="match_parent"
       android:layout_height="206dp"
       android:stackFromBottom="true"
       android:transcriptMode="alwaysScroll" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

</LinearLayout>

<EditText
    android:id="@+id/edit_text_out"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_weight="0.00"
    android:ems="10" />

<Button
    android:id="@+id/button_send"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="@string/send" />

 <ImageView
     android:id="@+id/imageView3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignBottom="@+id/textView2"
     android:layout_marginLeft="20dp"
     android:layout_toRightOf="@+id/textView2"
     android:src="@drawable/indicator" />

 <ImageButton
     android:id="@+id/imageButton2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignTop="@+id/imageButton4"
     android:layout_toRightOf="@+id/imageButton4"
     android:src="@drawable/rightbutton" />

 <ImageButton
     android:id="@+id/imageButton1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignTop="@+id/imageButton4"
     android:layout_toLeftOf="@+id/imageButton4"
     android:src="@drawable/leftbutton" />

 <ImageButton
     android:id="@+id/imageButton4"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_above="@+id/button_send"
     android:layout_centerHorizontal="true"
     android:src="@drawable/bottombutton" />

 <ImageButton
     android:id="@+id/imageButton3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_above="@+id/imageButton1"
     android:layout_toRightOf="@+id/imageButton1"
     android:src="@drawable/topbutton" />

 <TextView
     android:id="@+id/textView2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_above="@+id/imageButton3"
     android:layout_alignLeft="@+id/imageButton1"
     android:text="Connection:"
     android:textColor="#FFFFFF"
     android:textSize="20dp" />

  </RelativeLayout>


Here is my code for the java class for the buttons only, I left the on click codes blank because,I do not know the codes for the commands to the PC.

Java
@Override
  public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   if(D) Log.e(TAG, "+++ ON CREATE +++");

   // Set up the window layout
   setContentView(R.layout.main);

   ImageButton button1;
   ImageButton button2;
   ImageButton button3;
   ImageButton button4;

   button1 = (ImageButton) findViewById(R.id.imageButton1);
   button2 = (ImageButton) findViewById(R.id.imageButton2);
   button3 = (ImageButton) findViewById(R.id.imageButton3);
   button4 = (ImageButton) findViewById(R.id.imageButton4);

   //ImageButton 1

   button1.setOnClickListener(new OnClickListener() {
       public void onClick(View arg0) {
       }
   });

   //ImageButton 2

   button2.setOnClickListener(new OnClickListener() {
       public void onClick(View arg0) {
       }
   });

   //ImageButton 3

   button3.setOnClickListener(new OnClickListener() {
       public void onClick(View arg0) {
       }
   });

   //ImageButton 4

   button4.setOnClickListener(new OnClickListener() {
       public void onClick(View arg0) {
       }
   });
Posted
Updated 24-Nov-14 22:16pm
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900