我的Android应用程序在横向模式下工作。我有一个包含某些项目的列表视图。问题是只有当我单击项目名称时才调用setOnItemClickListener。我的意思是,如果我选择不是项目名称的行,则不会选择该项目,并且不会调用setOnItemClickListener。我该怎么办?
请帮我。提前致谢..
这是我的代码:
MyListView = (ListView) findViewById(R.id.MyListView);
MyListView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, playlists));
MyListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position,
long id) {
System.out.println("list touch "+ playlists[position]+" si id "+idPlaylist[position]);
dialogwait = ProgressDialog.show(Playlist.this, "Loading...","Please wait..", true);
Intent i = new Intent(getBaseContext(), ViewPlaylist.class);
i.putExtra("id",idPlaylist[position]);
i.putExtra("timer",timerPlaylist[position]);
startActivity(i);
finish();
}
});
最佳答案
如果您将列表中项目的某些视图放大,将xml布局中的宽度和高度设置为fill_parent
可以解决您的问题,
好吧,不要使用android.R.layout.simple_list_item_1
,因为您无法更改它...
你可以做
MyListView = (ListView) findViewById(R.id.MyListView);
MyListView.setAdapter(new ArrayAdapter<String>(this,
R.layout.mylistitem, playlists));
MyListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position,
long id) {
System.out.println("list touch "+ playlists[position]+" si id "+idPlaylist[position]);
dialogwait = ProgressDialog.show(Playlist.this, "Loading...","Please wait..", true);
Intent i = new Intent(getBaseContext(), ViewPlaylist.class);
i.putExtra("id",idPlaylist[position]);
i.putExtra("timer",timerPlaylist[position]);
startActivity(i);
finish();
}
});
那么R.layout.mylistitem可以是
<TextView android:id="@+id/sometitle"
android:layout_width="fill_parent"
android:layout_height="some_height_you_want" />
关于android - setOnItemClickListener用于横向模式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8010913/