[英]how can i set selected value from alert dialog (single selection) on my list view item?
How can i set selected value from alert dialog (single selection) on my list view item?... My scenario is: - I have listview item with button and textview - Clicking on button in my listview item , which opens dialog box - Selecting value from single selection list in dialog box - Want to show this selected value from dialog in textview inside my listview item如何从我的列表视图项上的警报对话框(单选)中设置选定的值?...我的场景是: - 我有带有按钮和文本视图的列表视图项 - 单击我的列表视图项中的按钮,打开对话框 - 选择对话框中单个选择列表中的值 - 想要在我的列表视图项内的 textview 中的对话框中显示此选定值
here is my code: Problem is: the value changed inside listitem view by setting in dialog box, doesnt persist on scroll up and down.这是我的代码: 问题是:通过在对话框中设置在列表项视图中更改的值,不会在上下滚动时持续存在。
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
db = new DatabaseHandler(getContext());
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.activity_event_item, parent, false);
holder = new ViewHolder();
holder.x = (TextView) convertView.findViewById(R.id.x);
holder.y = (TextView) convertView.findViewById(R.id.y);
holder.b = (Button) convertView.findViewById(R.id.b);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
String s = x[position];
if (s != null){
holder.x.setText("setting text");
}
holder.b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
selected = 0;
builder.setTitle("Select ").setSingleChoiceItems(array1, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
selected = which;
}
})
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
value = array1[selected];
holder.y.setText(value + " ");
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
builder.create();
builder.show();
}
});
return convertView;
}
I have achieved the same thing with this code我用这段代码实现了同样的目的
private void showDialoge(Context context, int postion) {
String[] items = {"Unpaid", " Paid "};
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setSingleChoiceItems(items, postion, null)
.setPositiveButton(R.string.ok_button_label, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
// Do something useful withe the position of the selected radio button
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.