मेरे पास मेरे एप्लिकेशन में GridView
है जिसमें मैं टेक्स्ट दिखाना चाहता हूं और ईमेल इनबॉक्स पेज की तरह बॉक्स देखना चाहता हूं। मैं इसके लिए एक एडाप्टर का उपयोग करता हूं लेकिन जब मैं 15 से अधिक तत्व दिखाता हूं तो शीर्ष पंक्तियों का टेक्स्ट और चेक बॉक्स गायब हो जाता है, इसलिए जब मैं फिर से ऊपर स्क्रॉल करता हूं तो वे दिखाई नहीं देते हैं। यहाँ मेरी कोडस्क्रॉलिंग के दौरान ग्रिड व्यू सामग्री गायब हो जाती है
public class EmployeeAdaptor extends BaseAdapter {
Context context;
String [] table;
int pos;
int formatOfTable;
public EmployeeAdaptor(Context c,String []tab,int numberOfItems,int format, boolean[] sel) {
context = c;
table = tab;
items = numberOfItems;
formatOfTable = format;
//ifformat is 0 then show text view in first column
//if it is 1 then show radio button in first column
//if it is 2 then show check box in first column.
pos = 0;
}
public int getCount() {
//
return items;
}
public Object getItem(int position) {
//
return position;
}
public long getItemId(int position) {
//
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View v;
TextView text = new TextView(context);
RadioButton radio = new RadioButton(context);
CheckBox check = new CheckBox(context);
if(convertView == null){
v = new View(context);
}
else{
v = convertView;
}
if(formatOfTable==2 && position%5==0 && position/5!=0){
check.setId(position/5);
v = check;
}
else if(formatOfTable==0 && position%5==0 && position/5!=0){
text.setText("");
v = text;
//To set blank text at first position when no need of check
}
else{
if(position%5!=0){
try{
v = text;
text.setText(table[pos]);
text.setTextColor(Color.BLACK);
text.setTextSize(20);
pos++;
}
catch(Exception e){
}
}
}
if(position/5==0){
text.setTypeface(Typeface.DEFAULT_BOLD);
}
return v;
}
}
वर्ग एडाप्टर कॉल के रूप में किया जाता है:
table.setAdapter(new EmployeeAdaptor(this, empTable, numberofboxes, 0, selected));
//OR
table.setAdapter(new EmployeeAdaptor(this, empTable, numberofboxes, 1, selected));
लेआउट एक्सएमएल फ़ाइल
<GridView
android:id="@+id/gridView1"
android:layout_width="wrap_content"
android:layout_height="360dp"
android:layout_marginTop="40dp"
android:numColumns="5" android:verticalSpacing="35dp">
</GridView>
क्या आप एडाप्टर द्वारा उपयोग किए गए एक्सएमएल लेआउट को दिखा सकते हैं? – Vicent
एडाप्टर गतिशील रूप से ऑब्जेक्ट को परिभाषित करता है इसलिए यहां XML लेआउट की आवश्यकता नहीं है। – ADCDER