开发者

Displaying a list with different types of information in Android

I want to create a page with X questions (the questions are stored in a da开发者_C百科tabase and I read them), headline and buttons at the end.

When the user clicks on one question than the question should transform into a dialog where the user can modify the question, however the other questions above and beneath it should still display the same way.

The way ListActivity is used in the sample notepad application in the android documentation it seems like the class can only display multiple items of the same type.

Is there a straightforward way to go about this problem?


I should tell you that I don't like your solution as an user. I would prefer to chose from a list and having an edit activity after a click. That's the default approach I've seen in every android app and it will be also easier for you.

If you still want to do what you explained I would try do this:

  • Create a ListView
  • Create a class QuestionOrDialog
  • Create an Adapter that extends from ArrayAdapter

Override getView doing something like:

QuestionOrDialog aQuestionOrDialog =  getItem(position);

if ( aQuestionOrDialog.showDialog() ) {
  return mInflater.inflate(R.layout.dialog, parent, false);
} else {
  view = mInflater.inflate(R.layout.question, parent, false);
  TextView question = (TextView) view.findViewById(R.id.question);
  question.setText(aQuestionOrDialog.getQuestion());
}
  • On the OnClick you will have to do a getItem() and set that it was clicked.
  • Tell the listView that it's item have changed.

Hope it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜