0
嘿请任何一个可以告诉我下面如何执行呼吁列表视图项的具体数目
我试图给监听器使用onContextItemSelected()在列表视图项的答案...
以下是我的代码..出了问题..pls建议一些帮助我。
我想在列表中不同数量的每个项目执行呼叫..
ListView listview1;
String Contacats[] = { "Rohini", "sonali", "Archana", "Dipti", "Maitri" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview1 = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, Contacats);
listview1.setAdapter(adapter);
registerForContextMenu(listview1);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("select the action");
menu.add(0, v.getId(), 0, "Call");
menu.add(0, v.getId(), 0, "SMS");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if(item.getTitle()=="Call"){
if(listview1.getAdapter().getItem(0)=="Rohini")
{
Intent phoneIntent = new Intent(Intent.ACTION_CALL);
phoneIntent.setData(Uri.parse("tel:91-909-600-3409"));
try {
startActivity(phoneIntent);
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"Call faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}
else if(listview1.getAdapter().getItem(0)=="Archana")
{
Intent phoneIntent = new Intent(Intent.ACTION_CALL);
phoneIntent.setData(Uri.parse("tel:91-956-680-3479"));
try {
startActivity(phoneIntent);
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"Call faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(getApplicationContext(),"calling code",Toast.LENGTH_LONG).show();
}
}
else if(item.getTitle()=="SMS"){
Toast.makeText(getApplicationContext(),"sending sms code",Toast.LENGTH_LONG).show();
}else{
return false;
}
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
为语言添加另一个标记 – daniele3004
为什么总是getItem(0)? –
这是我正在尝试,但没有得到实际的结果。我想匹配适配器中的项目与字符串(名称..ex..rohini)..然后执行调用它...同样的其他项目 –