popup dialog as input
Hey, I have a problem with implementing a popup dialog like this one in this example: http://malsandroid.blogspot.com/2010/04/list-picker-and-fading-popup-notice.html
Its working just fine if I implement the code for a editbox. The problem is, that I want to use a options menu in the app that lets the user control if he wants to use the standard keyboard in android or this popup dialog as input to the editboxes.
If i put this code directly into the main.java class it works fine as I just said ( same as code example above ):
hcp_entry_player_1 = (EditText)findViewById( R.id.hcp_entry_player_1 );
final CharSequence[] items = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a hcp");
builder.setItems(items, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialogInterface, int item)
{
hcp_entry_player_1.setText(items[item]);
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
return;
}
});
builder.create().show();
To make a long story short, when I use the options menu I need to use onClickListener between different void methods. Therefor I can not call AlertDialog.Builder builder = new AlertDialog.Builder(this);
. Ive tried to call AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
but it is not working. To be honest I dont realy understand the problem?.
I will type more code in case someone is interested:
public void setListInputMethod()
{
for( EditText et : mEditTextList )
{
et.setEnabled(false);
et.setOnClickListener(mTouchTextFieldListener);
}
}
private OnClickListener mTouchTextFieldListener = new OnClickListener()
{
EditText et;
public void onClick(View v)
{
et = (EditText)v;
final CharSequence[] items = {"1", "2", "3"};
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("Pick a hcp");
builder.setItems(items, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialogInterface, int item)
{
et.setText(items[item]);
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
return;
}
});
builder.create().show();
}
};
This method loops all edit-texts in the app and tries to set the popup dialog as input, but its not working as described abo开发者_Python百科ve. Realy need advice, thx in advance!
Instead of getApplicationContext()
, try storing the activity itself as a static variable and using it for the context.
In your class:
private static Activity activity;
Somewhere in onCreate()
:
activity = this;
Then do:
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
精彩评论