所以基本上我想这个列表视图被混洗,所以它总是随机的。但是每个人都需要打开自己的活动,无论它在列表视图中的位置是什么(所以我非常确定我不能使用位置)。所以我尝试使用(TextView)视图).getText( ),它不像它在吐司里那样读取它。有任何想法吗?从混洗列表视图中打开活动
public class Bands extends ListActivity{
int numBands;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ArrayList<String> bands = new ArrayList<String>();
bands.add(new String("Band0"));
bands.add(new String("Band1"));
bands.add(new String("Band2"));
Collections.shuffle(bands);
setListAdapter(new ArrayAdapter<String>(this, R.layout.item_list, bands));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
if(((TextView) view).getText() == "Band0"){
Intent i = new Intent(Bands.this, Audio.class);
i.putExtra("Band", 0);
startActivity(i);
}
}
});
}
}
任何人都知道的方式读取洗牌创建编号顺序?如果有人知道如何,可能是一种方法。感谢和任何帮助表示赞赏。
谢谢你的作品。 – steven
不客气,很高兴帮助! –