SORU
14 ŞUBAT 2012, Salı


"kaynak KİMLİĞİ TextView bir " olmasını gerektirir ArrayAdapter; xml sorunları

Benim görüntülemek istediğim dosya(metin dosyası) ListView ekran ayarlamaya çalışırken bir hata alıyorum. Xml ile ilgili bir şey vardır eminim. Ben sadece this.file = fileop.ReadFileAsList("Installed_packages.txt"); bilgileri görüntülemek istiyorum. Benim kod:

public class Main extends Activity {
    private TextView tv;
    private FileOperations fileop;
    private String[] file;

    /** Called when the activity is first created. */       
    @Override
    public void onCreate(Bundle savedInstanceState) {           
        super.onCreate(savedInstanceState); 
        this.fileop = new FileOperations(); 
        this.file = fileop.ReadFileAsList("Installed_packages.txt"); 
        setContentView(R.layout.main);
        tv = (TextView) findViewById(R.id.TextView01);
        ListView lv = new ListView(this);
        lv.setTextFilterEnabled(true); 
        lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, this.file)); 
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

              public void onItemClick(AdapterView<?> parent, View view,     int position, long id) { 
                    // When clicked, show a toast with the TextView text 
                    Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); 
              } 
        });         
        setContentView(lv);
    }

}

list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:padding="10dp"   
    android:textSize="16sp"   
    android:textColor="#000">

</LinearLayout>

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1">
<ScrollView
    android:id="@ id/SCROLLER_ID"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:fillViewport="true">
        <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:padding="5sp"
        android:id="@ id/TextView01"
        android:text="@string/hello"/>
    </ScrollView>

</LinearLayout>

CEVAP
14 ŞUBAT 2012, Salı


ArrayAdapter kaynak KİMLİĞİ TextView bir XML olması gerekiristisna ArrayAdapter beklediği kaynağı yok demektir. Kullandığınızda bu kurucu:

new ArrayAdapter<String>(this, R.layout.a_layout_file, this.file)

R.Layout.a_layout_file TextViewsadece bir(15**. xml düzeni içeren bir dosya kimliği olmalıdır ^strong>olamazbaşka bir düzen,*,* 17 ** 16 vs gibi!) tarafından alınmış, şöyle bir şey:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    // other attributes of the TextView
/>

Eğer listenizi isterseniz bir şey TextView basit bir widget biraz farklı o zaman satır düzeni bu oluşturucu kullanın:

new ArrayAdapter<String>(this, R.layout.a_layout_file, 
   R.id.the_id_of_a_textview_from_the_layout, this.file)

çeşitli görüşler içeren bir düzen id kaynağı, aynı zamandagerekirsatır düzeni Strings nereye koyacağımı böylece senin için ArrayAdapter geçmesi TextView id(üçüncü parametre) vardır.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • atKristaBradford

    atKristaBrad

    4 Aralık 2010
  • Gimpology.com Video Tutorials

    Gimpology.co

    3 ŞUBAT 2008
  • PamtheBlamofficial

    PamtheBlamof

    31 Aralık 2010