Guys, I'm having one hell of a time here trying to listen for the 'on 
click' for this ListView. Every single thing I've seen when searching 
Google, I've tried (or at least think I've tried). I've even set the 
TextView and ImageView in the XML to not be clickable or focusable, but 
that didn't work either.

I'm not at all opposed to completely rewriting the code, or the XML. What 
I'm looking for is a scrolling list with a thumbnail picture and a piece of 
text. I will be using a JSON response to fill the ImageView and some way to 
reference what was clicked so that I can open a new activity to display the 
larger sized photo and whatnot. But, since I'm incredibly new on the scene 
of Android app development, I finally caved to ask. 

Any help would be greatly appreciated.

MyGames.java
____________

package com.lifeofchance.bpt;


import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MyGames extends Activity {

    TextView btnDashboard;


    String[] text = {
        "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", 
"Nine", "Ten"
    };

    int[] image = {
        R.drawable.color_line,
        R.drawable.color_line,
        R.drawable.color_line,
        R.drawable.color_line,
        R.drawable.color_line,
        R.drawable.color_line,
        R.drawable.color_line,
        R.drawable.color_line,
        R.drawable.color_line,
        R.drawable.color_line
    };

    String[] gameId = {
        "12345", "32165", "65498", "98732", "14789", "36987"
    };

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.mygames);

        ListView l1 = (ListView) findViewById(R.id.listV);
        l1.setAdapter(new MyCustomAdapter(text, image, gameId));


        btnDashboard = (TextView) findViewById(R.id.btnDashboard);
        btnDashboard.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent i = new Intent(getApplicationContext(), 
DashboardActivity.class);
                startActivity(i);
                finish();
            }
        });

    }


    class MyCustomAdapter extends BaseAdapter {

        String[] data_text;
        int[] data_image;
        String[] data_id;

        MyCustomAdapter() {
            data_text = null;
            data_image = null;
            data_id = null;
        }

        MyCustomAdapter(String[] text, int[] image, String[] gameId) {
            data_text = text;
            data_image = image;
            data_id = gameId;
        }


        public int getCount() {
            return data_text.length;
        }

        public String getItem(int position) {
            return null;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup 
parent) {

            LayoutInflater inflater = getLayoutInflater();
            View row;

            row = inflater.inflate(R.layout.mygames_listview, parent, 
false);
            row.setLongClickable(true);
            row.setClickable(true);
            row.setFocusable(true);

            TextView textview = (TextView) 
row.findViewById(R.id.TextView01);
            ImageView imageview = (ImageView) 
row.findViewById(R.id.ImageView01);

            textview.setText(data_text[position]);
            imageview.setImageResource(data_image[position]);


            return (row);

        }

    }

}

mygames_listview.xml
___________________

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
android:layout_height="68dp"
android:gravity="left|center"
android:layout_width="fill_parent"
android:paddingBottom="5dp"
android:background="#9CCF31"
android:paddingTop="5dp"
android:paddingLeft="5dp">

<ImageView android:id="@+id/ImageView01"
android:layout_width="64dp"
android:layout_height="wrap_content">
</ImageView>

<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:textColor="#0099CC">
</TextView>

</LinearLayout>


And finally, mygames.xml
_____________________

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" 
xmlns:android="http://schemas.android.com/apk/res/android";>

<RelativeLayout
android:id="@+id/RelativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#ffffff" >

<!-- Header Starts -->
<LinearLayout
android:id="@+id/headbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/header_gradient"
android:focusable="true"
android:focusableInTouchMode="true"
android:paddingBottom="5dip"
android:paddingTop="5dip" >

<!-- Logo Start -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:src="@drawable/logo" />

<ImageView
android:id="@+id/cnwLogo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_marginLeft="10dip"
android:scaleType="fitCenter"
android:src="@drawable/webgoofy" />
<!-- Logo Ends -->
</LinearLayout>
<!-- Header Ends -->


<!-- Footer Start -->
<LinearLayout
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@layout/footer_repeat" >
</LinearLayout>
<!-- Footer Ends -->

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android";
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/headbar"
android:orientation="vertical"
android:padding="10dip" >

<ListView
android:id="@+id/listV"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:clickable="true"
android:fadingEdgeLength="0dp"
android:longClickable="true"
android:scrollbars="none"
android:smoothScrollbar="true"
android:transcriptMode="alwaysScroll" />

<TextView
android:id="@+id/btnDashboard"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_marginTop="15dip"
android:gravity="center"
android:padding="10dp"
android:text="Return to Dashboard"
android:textColor="#0b84aa"
android:textSize="20dip" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

<<attachment: ggroups.jpg>>

Reply via email to