Saturday, July 9, 2011

[android-developers] Lack of clicking in ListView

All,

I'm writing an app that has 3 tabs and a ListView as its first
screen. Here is a portion of the class that sets up the 3 tabs with
icons and then creates an intent for the MyList.class that is my
ListView class. This works. I can select the different tabs and it
switches between the three views. If I select the "Tracking" tab, I
get the ListView view.

Below the line of asterisks is a portion of code for the MyList
class. The issue is that I cannot select an item from the list. I
have seen examples where Listeners are used and examples where they
aren't used. This code DOESN'T have the listener. Is that why the
list is unresponsive? Or does it have something to do with the fact
that the ListView is part of the tabs scheme? I'ld love some
direction here....

btw, R.layout.rowlayout in the code is the .xml defining the rows in
the listview. Nothing special, 2 lines of text and a thin progress
bar. As I said before, the ListView pains and scrolls fine. It just
doesn't select.


Thanks

Tony

public class WritersPubs extends TabActivity {
long id;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.rowlayout);

Resources res = getResources(); // Resource object to get
Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab

// Create an Intent to launch an Activity for the tab (to be
reused)
// .
// removed the code for 2 tabs for brevity
// .
intent = new Intent().setClass(this, MyList.class);
spec = tabHost.newTabSpec("Tracking").setIndicator("Tracking",

res.getDrawable(R.drawable.ic_tab_tracking_selected))
.setContent(intent);
tabHost.addTab(spec);

tabHost.setCurrentTab(2);


**************************************************************************************************************************


public class MyList extends ListActivity {
boolean bPrompt = false;
boolean bDate = false;
boolean bNeither = true;
boolean bTextTrue = false;
boolean bUseStored = false;
boolean bRPrompt = false;
long id;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an array of Strings, that will be put to our ListActivity

String[] names = new String[] { "Linux", "Windows7", "Eclipse",
"Suse",
"Ubuntu", "Solaris", "Android", "iPhone" };
setListAdapter(new ArrayAdapter<String>(this, R.layout.rowlayout,
R.id.label, names));

}

@Override
protected void onListItemClick(ListView l, View v, int position,
long id) {
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
String os = o.toString();
Toast.makeText(this, "You have chosen OS: " + " " + os,
Toast.LENGTH_LONG).show();
}


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

No comments:

Post a Comment