我的应用中有一个ListView
,ListView
中的每个项目都包含一个按钮和项目计数。点击每个项目中的按钮,我想显示一个对话框EditText
输入相应项目的新计数,并使用我从对话EditText
字段获得的值更新项目。
我创建了对话框以在按钮点击时输入新计数,但无法更新该值。
我的适配器
public class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
return planList.size();
}
@Override
public Object getItem(int position) {
return planList.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final SalesModel db_data = planList.get(position);
if (convertView == null) {
convertView = View.inflate(getApplicationContext(), R.layout.return_confirm, null);
}
TextView name = (TextView) convertView.findViewById(R.id.name);
final TextView stock = (TextView) convertView.findViewById(R.id.stock);
TextView amount = (TextView) convertView.findViewById(R.id.amount);
ImageView minus = (ImageView) convertView.findViewById(R.id.minus);
Double count = Double.parseDouble(db_data.getStock());
Double price = Double.parseDouble(db_data.getSprice());
Double s_price = count*price;
String set_amount = s_price.toString();
name.setText(db_data.getName());
stock.setText(db_data.getStock());
amount.setText(set_amount);
minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
stock_return = ShowDialogue();
Double n_stock = Double.parseDouble(db_data.getStock())-Double.parseDouble(stock_return);
stock.setText(n_stock.toString());
}
});
return convertView;
}
}
显示对话的功能
public String ShowDialogue(){
String stk_val;
stock_return = "0.0";
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final AlertDialog dialog = builder.create();
dialog.setCancelable(false);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(this.LAYOUT_INFLATER_SERVICE);
View dialogLayout = inflater.inflate(R.layout.popup_reminder, null);
final EditText stk = (EditText)dialogLayout.findViewById(R.id.stock);
Button ok = (Button)dialogLayout.findViewById(R.id.later );
Button close = (Button)dialogLayout.findViewById(R.id.close);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(stk.getText().toString().trim().isEmpty()){
stk.setError("Enter quantity");
}
else {
stock_return = stk.getText().toString().trim();
}
}
});
dialog.setView(dialogLayout,0,0,0,0);
dialog.show();
return stock_return;
}
答案 0 :(得分:1)
试试这样:
let query = "Select [System.Id], [System.Title], [System.State]
From WorkItems Where [System.WorkItemType] = 'Bug'
order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc";
client.getQuery("DMPLM_TP1", query).then ((wi) => {}, (query) => {});
像这样改变对话框..
componentWillMount() {
console.log(`componentDidUpdate`, prevProps);
const user = firebase.auth().currentUser;
if (user != null) {
const db = firebase.firestore();
const docRef = db.collection('userCheckInHistory').doc(user.uid);
docRef
.get()
.then(doc => {
if (doc.exists) {
let shopId = this.props.shopId;
let userShopHistoryData = doc.data();
let userShopPick = userShopHistoryData[shopId];
this.setState({
checkInHistory: userShopPick,
shopId: this.props.shopId
});
} else {
console.log('No such document!');
return false;
}
})
.catch(function(error) {
console.log('Error getting document:', error);
});
}
}