Adapter
은 BaseAdapter
입니다. 클래스 내부 I 입력에 대한 사용자 정의 AlertDialog
EditText
두와의를 사용하는 것을 시도하고 내 응용 프로그램의 MainActivity
에서 방법어댑터 및 대화 상자에서보기
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.childitem, parent, false);
}
Product p = getProduct(position);
((TextView) view.findViewById(R.id.tvDescr)).setText(p.name);
((TextView) view.findViewById(R.id.tvPrice)).setText(p.price + "");
((ImageView) view.findViewById(R.id.ivImage)).setImageResource(p.image);
CheckBox cbBuy = (CheckBox) view.findViewById(R.id.cbBox);
cbBuy.setOnCheckedChangeListener(myCheckChangList);
cbBuy.setTag(position);
cbBuy.setChecked(p.box);
return view;
}
있다. 제대로 작동하지 않아 내 리소스에 액세스하기 위해 View
을 사용하도록 권장합니다.
void newItemInput(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
final View v = inflater.inflate(R.layout.dialog_signin, null);
builder.setView(v);
builder.setTitle("");
builder.setMessage("");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
EditText item_name = (EditText) v.findViewById(R.id.item_name);
EditText item_price =(EditText) v.findViewById(R.id.item_price);
String text = item_name.getText().toString();
String text_price = item_price.getText().toString();
int price = Integer.parseInt(text_price);
// Do something with value!
products.add(new Product(text, price, R.drawable.unread, false));
item_name.setText("");
item_price.setText("");
}
});
는 지금은 Dialog
의 데이터가 다음 문에서 인수로 사용할 삽입 할 때 : products.add (새 제품 (텍스트, 가격, R.drawable.unread, 거짓)); ... 이상한 행동을합니다. 어댑터와 대화 상자에서 View
호출 사이의 모순 때문에 발생합니까? 그렇다면 그것을 해결하기 위해 무엇을 할 수 있습니까?
는 '제품의 제품 또는 어댑터의 목록입니다? 또한 이상한 방법으로 말할 때 정확히 어떻게됩니까? – jimmithy
ArrayList 제품 = 새로운 ArrayList (); 이상한 것은 ListView에서 새 항목을 만들기 위해 대화 상자의 텍스트와 가격을 인수로 지정한다는 의미이며 첫 번째 항목은 두 번째 작업을 수행 할 때만 제공됩니다. 예를 들어 text = a; price = 0 (대화 상자의 첫 번째 호출), text = b, price = 1 (두 번째 호출). 두 번째로 먼저 들어 왔을 때 firts plase에 나타나지 않았습니다. 두 번째는 보이지 않으며 세 번째는 기다립니다. 나는 두 번째 것이 입력되지 않을 때까지 처음에는 숨겨 졌다고 가정합니다. –
user1706819
이것을 해결할 수 있습니까? 나는 안드로이드에서 새로운 사람입니다. – user1706819