這裏是代碼,這就是列表視圖! 謝謝! **我想從列表中的行獲取信息,並在新的活動
打開它的代碼handele ListView,並且有持有單項視圖android:如何在新的活動中從列表視圖中打開項目?
public class HelpFriends extends Activity
{
ListView dilemasListView;
MyCustomListAdapter customListAdapter;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.help_friends);
dilemasListView = (ListView) findViewById(R.id.dilemasListView);
HMCApplication myApp = (HMCApplication)getApplication();
myApp.getAllDilemasFromServer();
ArrayList<Dilema> myDilemas = myApp.getDilemas();
//dilemasListView.setOnItemClickListener(this);
customListAdapter = new MyCustomListAdapter(this,
R.layout.dilema_list_layout, // layout of a single item in the list
myDilemas);
dilemasListView.setAdapter(customListAdapter);
}
// the adapter handles the list
public class MyCustomListAdapter extends ArrayAdapter<Dilema>
{
// internal list of data
ArrayList<Dilema> mItems;
public MyCustomListAdapter(HelpFriends theActivity,
int viewResourceId, ArrayList<Dilema> objects)
{
super((Context) theActivity, viewResourceId, objects);
mItems = objects;
}
@Override
public int getCount()
{
return mItems.size();
}
@Override
public Dilema getItem(int position)
{
return mItems.get(position);
}
@Override
public int getPosition(Dilema item)
{
return mItems.indexOf(item);
}
@Override
public long getItemId(int position)
{
return position;
}
// getView returns/creates the view for a SINGLE item in the list
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// theUser will be the logic object with all data
Dilema theDilema = mItems.get(position);
// row will be the visual object
LayoutInflater inflater = getLayoutInflater();
// single_fruit_item_layout is the layout of a single row
View row = inflater.inflate(R.layout.dilema_list_layout, parent, false);
// populate the row object from theUser object
TextView TextVieUsername = (TextView) row.findViewById(R.id.usernameText);
TextVieUsername.setText(theDilema.getUsername());
TextView TextViewQuestion = (TextView) row.findViewById(R.id.questionText);
TextViewQuestion.setText(theDilema.getQuestion());
TextView TextViewTime = (TextView) row.findViewById(R.id.timeText);
TextViewTime.setText(theDilema.getTime());
TextView TextViewCategory = (TextView) row.findViewById(R.id.categoryText);
TextViewCategory.setText(theDilema.getCategory());
return row;
}
}
}
謝謝你,你幫我很多! – user3111912
也許你可以告訴我我是如何從列表中的每一行獲取數據並將其顯示在新的活動中? – user3111912