ورود

View Full Version : ساخت Listview دارای SubTitle



reza_devel0per
شنبه 26 دی 1394, 07:25 صبح
من با استفاده از کدهای زیر یک لیست همراه با subtitle درست کردم. ولی از اونجایی که در این کد ، کلاس view از ListActivity ارث می بره ، بقیه ابزارهایی که روی فرم گذاشته بودم مثل دکمه ها، دیده نمیشه.
اگه ممکنه راهنماییم کنید که چطور می تونم کاری کنم که در همون حالت ارث بری از ActionBarActivity و با استفاده از ListView میشه این کار رو کرد/
public class CustomTwoLineListActivity extends ListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

final List<String[]> colorList = new LinkedList<String[]>();
colorList.add(new String[] { "Red", "the color red" });
colorList.add(new String[] { "Green", "the color green" });
colorList.add(new String[] { "Blue", "the color blue" });

// Note - we're specifying android.R.id.text1 as a param, but it's ignored
// because we override getView(). That param usually tells ArrayAdapter
// where to find the one TextView entity in a complex layout.
// If our layout was a simple TextView (like android.R.layout.simple_list_item_1),
// we wouldn't need that param.
setListAdapter(new ArrayAdapter<String[]>(
this,
android.R.layout.simple_list_item_2,
android.R.id.text1,
colorList) {

@Override
public View getView(int position, View convertView, ViewGroup parent) {

// Must always return just a View.
View view = super.getView(position, convertView, parent);

String[] entry = colorList.get(position);
TextView text1 = (TextView) view.findViewById(android.R.id.text1);
TextView text2 = (TextView) view.findViewById(android.R.id.text2);
text1.setText(entry[0]);
text2.setText(entry[1]);
return view;
}
});
}
}
ممنون از راهنمایی شما

JYasProgramer
چهارشنبه 30 دی 1394, 11:28 صبح
سلام
CustomTwoLineListActivity رو در فایل بیانیه چجوری تعریف کردی؟؟
واسش تم تعریف کن مثلا:


<application

android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
>

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
</application>
حالا android:theme="@style/AppTheme" رو در style اینگونه تعریف کن

<style name="AppTheme" parent="android:Theme.Holo">