Reputation: 6931
I want to open a Custom Dialog() when my Custom list view item is clicked.
I tried so far but can't open the dialog. Here is code details:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.input_dialog);
dialog.setTitle("What about Today!");
**//initialize custom dialog items.**
EditText mood = (EditText) dialog.findViewById(R.id.editTextyourMode);
Button btnSaveButton = (Button) dialog
.findViewById(R.id.btnSaveMyMoods);
Button btnClear = (Button) dialog
.findViewById(R.id.btnClear);
dialog.show();
}
here is custom Array adapter getView(...) method.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.sell_info_list, parent, false);
TextView product_id = (TextView) rowView.findViewById(R.id.product_id);//
product_id.setText(products.get(position).getProduct_id());
EditText product_quantity = (EditText) rowView
.findViewById(R.id.editTextQuantity);
return rowView;
}
Finally,I want to open this dialog whenList view item edit text is clicked. Anyone help me?
Upvotes: 1
Views: 4808
Reputation: 4705
In Adpter write this code
EditText product_quantity = (EditText) convertView
.findViewById(R.id.editTextQuantity);
product_quantity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.input_dialog);
dialog.setTitle("What about Today!");
//initialize custom dialog items.**
EditText mood = (EditText) dialog.findViewById(R.id.editTextyourMode);
Button btnSaveButton = (Button) dialog
.findViewById(R.id.btnSaveMyMoods);
Button btnClear = (Button) dialog
.findViewById(R.id.btnClear);
dialog.show();
}
});
Upvotes: 0
Reputation: 6931
i open the dialog typing from these inside getView(...) in Adapter and also can showing on the selected listview item EditText.
rowView.setClickable(true);
rowView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog = new Dialog(context);
dialog.setContentView(R.layout.input_dialog);
dialog.setTitle("What about Today!");
final EditText txtMode = (EditText) dialog
.findViewById(R.id.editTextyourMode);
Button btnSave = (Button) dialog
.findViewById(R.id.btnSaveMyMoods);
btnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String data = txtMode.getText().toString();
product_quantity.setText(data);
dialog.dismiss();
Log.d("data", data);
}
});
dialog.show();
}
});
Then the Screen look like that.
Now facing a problem.My List View has just 10 items.When i scrolling the list view,the item text vanish which is unseen
Thanks every one for sharing knowledge.**
Upvotes: 1
Reputation: 1600
Sorry I didnt see you were using a CustomAdapter, do this in the adapter
rowView.setClickable(true);
rowView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View paramView)
{
//if you want you can use the "position" value to get the desired row items.
}
});
Upvotes: 1
Reputation: 2421
set an onclick listener on your edit text and if it doesn't pop any dialog try setting the settings of your edittext android:focusable = "false" that is if u already put an listener on your edit text and still nothing happens
Upvotes: 1
Reputation: 7087
Try:
// Click event for single list row
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
EditText edit = (EditText) (findViewById(R.id.editText));
if (edit != null) {
edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "CLICKED",
Toast.LENGTH_LONG).show();
}
});
} else {
Toast.makeText(MainActivity.this, "EditText not found",
Toast.LENGTH_LONG).show();
}
}
});
Upvotes: 1