मैं गतिशील रूप से ListView
पर आइटम जोड़ता हूं और स्क्रॉल किए बिना सभी आइटम हमेशा दिखाना चाहता हूं।क्या सूची में स्क्रॉल को अक्षम करना संभव है?
लेआउट कोड:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/recipe_inside"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="16dp"
android:src="@drawable/head_cella" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="41dp"
android:background="@drawable/body_cella"
android:gravity="center_horizontal"
android:paddingTop="5dp"
android:text="Remember to save before leaving this page or inserted/modified data will be lost."
android:textColor="#000000"
android:textSize="13dp" />
<ImageView
android:id="@+id/ImageView01"
android:layout_width="match_parent"
android:layout_height="16dp"
android:layout_marginTop="30dp"
android:src="@drawable/head_cella" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@drawable/body_cella"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="Category"
android:textColor="#000000"
android:textSize="15dp" />
<Spinner
android:id="@+id/category_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/ImageView02"
android:layout_width="match_parent"
android:layout_height="16dp"
android:layout_marginTop="30dp"
android:src="@drawable/head_cella" />
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@drawable/body_cella"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="Name"
android:textColor="#000000"
android:textSize="15dp" />
<EditText
android:id="@+id/recipe_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Recipe title" android:lines="1"/>
<ImageView
android:id="@+id/ImageView03"
android:layout_width="match_parent"
android:layout_height="16dp"
android:layout_marginTop="30dp"
android:src="@drawable/head_cella" />
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@drawable/body_cella"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="Ingredients"
android:textColor="#000000"
android:textSize="15dp" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" android:cacheColorHint="#00000000" android:divider="#00000000"
android:isScrollContainer="false"
>
</ListView>
<Button
android:id="@+id/button_ing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" android:background="@drawable/add_recipe_button" android:onClick="addItems"/>
</LinearLayout>
</ScrollView></LinearLayout>
वर्ष OnCreate() समारोह कोड:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.add_recipe_form);
spinner = (Spinner)myhead.findViewById(R.id.category_spinner);
Cursor cursor = mydb.getCategoriesList();
ArrayList<Category> list = new ArrayList<Category>();
list.add(new Category(0,"Choose a category"));
while (cursor.moveToNext()) {
list.add(new Category(cursor.getInt(0),cursor.getString(1)));
}
// Step 2: Create and fill an ArrayAdapter with a bunch of "State" objects
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, list);
// Step 3: Tell the spinner about our adapter
spinner.setAdapter(spinnerArrayAdapter);
spinner.setOnItemSelectedListener(this);
setListAdapter(adapter);
ingredients.add((View)findViewById(R.layout.row_add_recipe));
adapter.notifyDataSetChanged();
}
अगर मैं कोड डेटाबेस डेटा के साथ मेरी स्पिनर को भरने के लिए संबंधित ले जाते हैं, यह मुझे हमेशा एक NullPointerException रिटर्न के रूप में यह नहीं है मेरे लेआउट में मिला। इसलिए मैं और इसे यहाँ रखने की जरूरत है समाधान मेरी ListView को addHeaderView() जोड़ने ठीक हो रहा है, लेकिन मैं अपने सिर लेआउट के बारे में एक और NullPointerException है:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.add_recipe_form);
ListView mylistview = (ListView) findViewById(android.R.id.list);
LinearLayout myhead = (LinearLayout)findViewById(R.id.linear_form);
mylistview.addHeaderView(myhead);
spinner = (Spinner)myhead.findViewById(R.id.category_spinner);
Cursor cursor = mydb.getCategoriesList();
ArrayList<Category> list = new ArrayList<Category>();
list.add(new Category(0,"Choose a category"));
while (cursor.moveToNext()) {
list.add(new Category(cursor.getInt(0),cursor.getString(1)));
}
// Step 2: Create and fill an ArrayAdapter with a bunch of "State" objects
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, list);
// Step 3: Tell the spinner about our adapter
spinner.setAdapter(spinnerArrayAdapter);
spinner.setOnItemSelectedListener(this);
setListAdapter(adapter);
ingredients.add((View)findViewById(R.layout.row_add_recipe));
adapter.notifyDataSetChanged();
}
'स्क्रॉल किए बिना सभी आइटम दृश्यमान करें' क्या होगा यदि आपके स्क्रीन आकार से अधिक आइटम हैं? –
क्या आप इसे अधिक विस्तार से समझा सकते हैं? जब आप स्क्रीन प्रदर्शित करने के लिए बहुत अधिक आइटम जोड़ते हैं तो आपके आइटम को कैसे प्रदर्शित किया जाना चाहिए (उदा। आपने 100 आइटम जोड़े)? – Sprigg
मेरी सूची दृश्य एक लाइनरलेआउट के अंदर है जिसमें अन्य तत्व हैं, जो स्क्रॉलव्यू में हैं। – dany84