在ListView项目上打开一个对话框,单击
每次点击
ListView
项目我想打开一个Dialog
。
这段代码不起作用,我真的找不到错误。请帮忙!
private void loadFeed(){
try{
BaseFeedParser parser = new BaseFeedParser();
messages = parser.parse();
List<String> descriptions = new ArrayList<String>();
List<String> titles = new ArrayList<String>(messages.size());
for (Message msg : messages){
descriptions.add(msg.getDescription());
titles.add(msg.getTitle() + "n" +msg.getDate());
}
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, R.layout.row,titles);
this.setListAdapter(adapter);
} catch (Throwable t){
Log.e("AndroidNews",t.getMessage(),t);
}
}
@Override
protected void onListItemClick(ListView descriptions,
View v, int position, long id) {
super.onListItemClick(descriptions, v, position, id);
String description = descriptions.get(position);
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.single);
dialog.setTitle("Blog");
dialog.setCancelable(true);
TextView text = (TextView) dialog.findViewById(R.id.TextView1);
text.setText(description);
dialog.show();
}
使用此代码运行应用程序,对话框显示说明,但说明也显示在列表项中。
messages = parser.parse();
List<String> titles = new ArrayList<String>(messages.size());
for (Message msg : messages){
titles.add(msg.getTitle() + "n" +msg.getDate() + "nn" + msg.getDescription());
}
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, R.layout.row,titles);
this.setListAdapter(adapter);
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String selection = l.getItemAtPosition(position).toString();
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.row2)
dialog.setCancelable(true);
TextView text = (TextView) dialog.findViewById(R.id.SinglePost);
text.setText(selection);
dialog.show();
}
没有找到相关结果
已邀请:
2 个回复
碉罕城爸
和
不存在方法
。 编辑: 您似乎混淆了ListView类和List接口。这是两件完全不同的事情! 实现
接口的类(如
)在您的情况下保存对象,而
类是Android小部件,它在列表表示中显示
s。 我真的建议你通过Hello Views教程部分,以便在深入了解更复杂的内容之前,先了解Android视图。
靛新比比催