我主要是想讓 list view 的內容可以隨意拖拽,所以裡面的list是隨機排列的。不管list在list view裡面如何排列,每個list都必須打開自己特定不變的activity。所以我試著使用(TextView)view.getText()來讀取list的信息,但是正如在Toast裡面的情況一樣,我無法得到每條list的對應信息。
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);
}
}
});
}
}
誰知道如何讀取可拖拽對象內容的排列順序?
做下面的改變:
String text = ((TextView) view).getText();
if (text.equals("Band0") {