android长按ListView弹出一个窗口显示选择的item中的内容
publicclassMainActivityextendsActivity{privateListViewlist=null;privateSimpleAdapters...
public class MainActivity extends Activity {
private ListView list=null;
private SimpleAdapter sa=null;
private String tag[]={"尕、苯尒陔..","243。吴其值","119。杨勇","6号病床|强迫症","毛孩子","243。邹玄"};
private String tag1[]={"憧憬着下车那","憧憬着下车那.....","下车那......","憧憬着.......","那一刻.......","小孩和
private int pic[] ={R.drawable.list1,R.drawable.list2,R.drawable.list3,R.drawable.list4,R.drawable.list5,R.drawable.list6};
private List<Map<String,String>> map=new ArrayList<Map<String,String>>();
private EditText ed1,ed2;
private TextView tv1,tv2;
private Dialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i=0;i<tag.length;i++){
Map<String,String> map1 = new HashMap<String,String>();
map1.put("Photo", String.valueOf(pic[i]));
map1.put("Name", tag[i]);
map1.put("Take", tag1[i]);
map.add(map1);
}
sa = new SimpleAdapter(this,map,R.layout.qqlist,new String[]{"Photo","Name","Take"}
,new int[]{R.id.imageView1,R.id.textView1,R.id.textView2});
list = (ListView)findViewById(R.id.listView1);
list.setAdapter(sa);
tv1=(TextView) findViewById(R.id.textView1);
tv2=(TextView) findViewById(R.id.textView2);
ed1=(EditText) findViewById(R.id.editText1);
ed2=(EditText) findViewById(R.id.editText2);
list.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Map<String, String> mapl=(Map<String, String>) MainActivity.this.sa.getItem(arg2);
String name=mapl.get("Name");
String take=mapl.get("Take");
LayoutInflater flater = LayoutInflater.from(MainActivity.this);
View myView = flater.inflate(R.layout.log, null);
//ed1.setText(name);
//MainActivity.this.ed1.setText(name);
//MainActivity.this.ed2.setText(take);
MainActivity.this.dialog = new AlertDialog.Builder(MainActivity.this)
.setTitle("Login")
//.setMessage(name+"/t"+take)
.setIcon(R.drawable.ic_launcher).setNegativeButton("取消", null)
.setView(myView).create();
dialog.show();
return false;
}
});
}
}
这里读取name和take,已经读出来了,怎么把他们显示在弹出框里的EditText组件ed1和ed2中我这一运行就关闭不知道怎么改 展开
private ListView list=null;
private SimpleAdapter sa=null;
private String tag[]={"尕、苯尒陔..","243。吴其值","119。杨勇","6号病床|强迫症","毛孩子","243。邹玄"};
private String tag1[]={"憧憬着下车那","憧憬着下车那.....","下车那......","憧憬着.......","那一刻.......","小孩和
private int pic[] ={R.drawable.list1,R.drawable.list2,R.drawable.list3,R.drawable.list4,R.drawable.list5,R.drawable.list6};
private List<Map<String,String>> map=new ArrayList<Map<String,String>>();
private EditText ed1,ed2;
private TextView tv1,tv2;
private Dialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i=0;i<tag.length;i++){
Map<String,String> map1 = new HashMap<String,String>();
map1.put("Photo", String.valueOf(pic[i]));
map1.put("Name", tag[i]);
map1.put("Take", tag1[i]);
map.add(map1);
}
sa = new SimpleAdapter(this,map,R.layout.qqlist,new String[]{"Photo","Name","Take"}
,new int[]{R.id.imageView1,R.id.textView1,R.id.textView2});
list = (ListView)findViewById(R.id.listView1);
list.setAdapter(sa);
tv1=(TextView) findViewById(R.id.textView1);
tv2=(TextView) findViewById(R.id.textView2);
ed1=(EditText) findViewById(R.id.editText1);
ed2=(EditText) findViewById(R.id.editText2);
list.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Map<String, String> mapl=(Map<String, String>) MainActivity.this.sa.getItem(arg2);
String name=mapl.get("Name");
String take=mapl.get("Take");
LayoutInflater flater = LayoutInflater.from(MainActivity.this);
View myView = flater.inflate(R.layout.log, null);
//ed1.setText(name);
//MainActivity.this.ed1.setText(name);
//MainActivity.this.ed2.setText(take);
MainActivity.this.dialog = new AlertDialog.Builder(MainActivity.this)
.setTitle("Login")
//.setMessage(name+"/t"+take)
.setIcon(R.drawable.ic_launcher).setNegativeButton("取消", null)
.setView(myView).create();
dialog.show();
return false;
}
});
}
}
这里读取name和take,已经读出来了,怎么把他们显示在弹出框里的EditText组件ed1和ed2中我这一运行就关闭不知道怎么改 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询