آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

عدم نمایش list view ‌

mna24  11 سال پیش  11 سال پیش
0 0

سلام 

من پروژه Listview  را طبق آموزش انجام دادم ولی وقتی اجرا میکنم listview‌ را نشان نمیدهد و فقط یک text‌ که بالای پنجره main  بوده است نشان میدهد

public class ActivityMain extends Activity {

 

    public ArrayList<StructNote> notes = new ArrayList<StructNote>();

    public ArrayAdapter          adapter;

 

 

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        ListView lstContent = (ListView) findViewById(R.id.lstContent);

        adapter = new AdapterNote(notes);

        lstContent.setAdapter(adapter);

        for (int i = 10; i < 10; i++) {

            StructNote note = new StructNote();

            note.title = "Title " + i;

            note.description = "Description " + i;

            note.done = false;

            notes.add(note);

        }

        adapter.notifyDataSetChanged();

 

    }

}

 

 

 

 

0 0
دوست عزیز لطفا ویرایش کنید و برای درج کد توی ایتور حتما از کلید درج کن استفاده کن و قبل از این که سوال بپرسی راهنما رو بخونید . ممنون و متشکر . موفق باشید (11 سال پیش)
 برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال 
mna24  11 سال پیش
0 0

 

------------------- main activity --------------------------------
 import java.util.ArrayList;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;publicclassActivityMainextendsActivity{publicArrayList<StructNote> notes =newArrayList<StructNote>();publicArrayAdapter adapter;@Overridepublicvoid onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState); setContentView(R.layout.main);ListView lstContent =(ListView) findViewById(R.id.lstContent); adapter =newAdapterNote(notes); lstContent.setAdapter(adapter);for(int i =10; i <10; i++){StructNote note =newStructNote(); note.title ="Title "+ i; note.description ="Description "+ i; note.done=false; notes.add(note);} adapter.notifyDataSetChanged();}}

------------------------------ main.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"><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello"/><ListView android:id="@+id/lstContent" android:layout_width="match_parent" android:layout_height="wrap_content"><!--Preview: listitem=@layout/adapter_notes --></ListView></LinearLayout>
-------------------------------------------------------------------------------


پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .