2012-10-10 3 views
0

AdapterBaseAdapter입니다. 클래스 내부 I 입력에 대한 사용자 정의 AlertDialogEditText 두와의를 사용하는 것을 시도하고 내 응용 프로그램의 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 호출 사이의 모순 때문에 발생합니까? 그렇다면 그것을 해결하기 위해 무엇을 할 수 있습니까?

+0

는 '제품의 제품 또는 어댑터의 목록입니다? 또한 이상한 방법으로 말할 때 정확히 어떻게됩니까? – jimmithy

+0

ArrayList 제품 = 새로운 ArrayList (); 이상한 것은 ListView에서 새 항목을 만들기 위해 대화 상자의 텍스트와 가격을 인수로 지정한다는 의미이며 첫 번째 항목은 두 번째 작업을 수행 할 때만 제공됩니다. 예를 들어 text = a; price = 0 (대화 상자의 첫 번째 호출), text = b, price = 1 (두 번째 호출). 두 번째로 먼저 들어 왔을 때 firts plase에 나타나지 않았습니다. 두 번째는 보이지 않으며 세 번째는 기다립니다. 나는 두 번째 것이 입력되지 않을 때까지 처음에는 숨겨 졌다고 가정합니다. – user1706819

+0

이것을 해결할 수 있습니까? 나는 안드로이드에서 새로운 사람입니다. – user1706819

답변

0

어댑터가 유지 관리하는 데이터를 변경할 때 어댑터의 notifyDataSetChanged 메서드를 호출해야합니다. 연결된 뷰에 데이터가 변경되었고 자체적으로 새로 고쳐 져야 함을 알립니다. 이상한 동작은 목록에 새 항목을 추가하는 과정에서 호출되지만 항목이 추가 된 후에는 호출되지 않기 때문입니다. 어댑터 사용에 대한

자세한 내용은 여기에서 찾을 수 있습니다 : http://developer.android.com/guide/topics/ui/declaring-layout.html#AdapterViews

+0

고마워요. 그건 내 실수 였고 이미 관리 해왔다. – user1706819

+0

나는 그것을 onClick 내부에서해야만했지만 어쨌든 다시 한 번 감사드립니다. – user1706819

관련 문제