2013-08-18 1 views
0

Android 목록보기의 모든 행에 번호 선택 도구를 추가하는 방법을 배우고 자합니다.번호 선택 도구가있는 Android 목록보기

목록보기 코드는 다음과 같습니다

ListView barcodeList = (ListView) findViewById(R.id.listView1); 
       barcodeList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, bcResultArray)); 
+0

당신이 numberpicker 무엇을 의미합니까합니다 (numberPicker 포함) 내가 각 라인에 표시 할 구성 요소가? – Pavlos

+0

다음과 같은 목록보기가 필요합니다. http://img706.imageshack.us/img706/7056/nti8.jpg – Igor

+0

목록보기에 대해 고유 한 어댑터를 작성한 다음 그에 맞게 채워야합니다! 어댑터를 사용하는 것은 쉽지 않을 것입니다! 여기에서 기본 사항을 배울 수 있습니다. http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ – Pavlos

답변

0

BaseAdapter를 확장하여, 자신의 어댑터를 작성,이

가의 getView()에서 목록보기를 부풀려 모든 것을 더 명확하게해야하며, 모든 사용자 정의 할 수 있습니다 이리. getItem (int index)은 목록 항목의 내용이있는 객체를 반환합니다.

+0

더 명확히 할 수 있습니까? 몇 가지 코드를 추가하거나 튜토리얼을 링크 하시겠습니까? – Igor

2

숫자 선택기는 사용한 적이 없지만 다른 모든 것과 같이 작동합니다.

어댑터를 직접 만들어야합니다. ArrayAdaptergetView() methode에서 예를 들어를 사용하는 대신 레이아웃을 부 풀릴 수 있습니다. 나는 몇 가지 작은 변화를했기 때문에 그것은 일

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout [...] > 

    <TextView 
     [...] /> 

    <TextView 
     [...] /> 

    <NumberPicker 
     [...] /> 


</RelativeLayout> 
+0

내 친구 덕분에, 그것은 매력처럼 작동 !! – Igor

0

, 나는 여기에 코드를 공유합니다 : android.R.layout.simple_list_item_1

public class MyXYZAdapter extends ArrayAdapter<XYZ> { 
    //other stuff 
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View v = convertView; 

     if (v == null) { 
      LayoutInflater li = (LayoutInflater)  
      c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      v = li.inflate(R.layout.list_item_xyz, null); 
     } 

     //Object o = v.findViewById(...); 

     return v; 

    } 
    //other stuff 
} 

은 이제 list_item_xyz.xml 레이아웃 파일을 작성해야 . listalayout.xml은

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 

    // We came from the scanning activity; the return intent contains a RESULT_EXTRA key 
    // whose value is an ArrayList of BarcodeResult objects that we found while scanning. 
    // Get the list of objects and add them to our list view. 
    if (resultCode == RESULT_OK) 
    {   

     ArrayList<BarcodeResult> barcodes = data.getParcelableArrayListExtra(BarcodeScanActivity.RESULT_EXTRA); 
     if (barcodes != null) 
     { 
      for (int i =0;i<barcodes.size();i++) 
      { 
       bcResultArray.add(barcodes.get(i).barcodeString); 

      } 

      ListView barcodeList = (ListView) findViewById(R.id.listView1); 
      ListAdapter customAdapter = new MyXYZAdapter(this, R.layout.listalayout, bcResultArray); 
      barcodeList.setAdapter(customAdapter); 
     } 
    } 
} 

public class MyXYZAdapter extends ArrayAdapter<String> { 
    private final List<String> list; 

    public MyXYZAdapter(Context context, int resource, List<String> items) { 
     super(context, resource, items); 
     list = items; 

    } 

    //other stuff 
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View v = convertView; 

     if (v == null) { 

      LayoutInflater vi; 
      vi = LayoutInflater.from(getContext()); 
      v = vi.inflate(R.layout.listalayout, null); 

     } 

     TextView tv1 = (TextView) v.findViewById(R.id.lltitulo); 
     tv1.setText(list.get(position)); 
     NumberPicker np = (NumberPicker) v.findViewById(R.id.numberPicker1); 
     np.setMaxValue(999); 
     np.setMinValue(0); 
     np.setValue(1); 
     return v; 

    } 
    //other stuff 
}