I am trying to implement a contacts application. Here's the source :
call = (Button) findViewById(R.id.button3);
message = (Button) findViewById(R.id.button4);
call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerForContextMenu(call);
openContextMenu(call);
}
});
message.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerForContextMenu(message);
openContextMenu(message);
}
});
Now, this is the Context menu part :
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenu.ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu,v,menuInfo);
String num1 = ((TextView)findViewById(R.id.num1)).getText().toString();
String num2 = ((TextView)findViewById(R.id.num2)).getText().toString();
if(v == call)
{
menu.setHeaderTitle("Call");
menu.add(0,v.getId(),0,num1);
if(num2 != "")
{
menu.add(0,v.getId(),0,num2);
}
}
else if(v == message)
{
menu.setHeaderTitle("Message");
menu.add(0,v.getId(),0,num1);
if(num2 != "")
{
menu.add(0,v.getId(),0,num2);
}
}
}
The main functionality is , If the user has only one contact no, then only one number should be shown in the context menu. But, THIS is the problem :
It shows a blank space if there's no 2nd contact no. And, it's clickable !
My LOGIC : I am using TextView for showing the numbers stored in database. And I am using String to store the data of the TextView. If the 2nd number's String is not null, then add the item to the context menu.
Please help me with this ! Thanks in advance.