如何使用数组适配器,如下所示:
1- ..... extends ArrayAdapter
2 -
Context context;
int layoutResourceId;
int layoutResourcetext;
List<String> Favorites_strings;
Typeface tf;
3 -
(这,R.layout.row_layoutfavorites,R.id.textt,Favorites_strings,“fonts / Mj_Beirut.TTF”)
答案 0 :(得分:0)
public class AFavorites extends Activity {
TextView TextViewonvan;
EditText search;
EditText editTextSearch;
TextView textviewonvanehdialog;
TextView textviwedialogmessag;
ImageButton imagebutton;
public int Subjects_total_number;
public Globals global = new Globals();
public List<String> Favorites_numbers;
public List<String> Favorites_strings;
String each_subject;
public String[] Subjects;
TextView onvan;
TextView population;
Typeface tf;
// List view
private ListView lv;
// List view Adapter
ArrayAdapter<String> adapter;
CustomAdapter adapter1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.favorites);
tf = Typeface.createFromAsset(getAssets(), "fonts/Mj_Beirut.TTF");
onvan=(TextView)findViewById(R.id.TextViewonvanf);
onvan.setTypeface(tf);
onvan.setText("favorites ");
search=(EditText)findViewById(R.id.etsearchh);
imagebutton=(ImageButton)findViewById(R.id.ibsearchh);
Favorites_strings = new ArrayList<String>();
Favorites_numbers = new ArrayList<String>();
final SharedPreferences shared = getSharedPreferences("Prefs", MODE_PRIVATE);
Subjects_total_number = global.Subjects_total_number;
for(int x = 0; x < Subjects_total_number+1; x = x+1)
{
each_subject = "subject_" + String.valueOf(x);
if(b)
{
String this_subject = "subject_" + String.valueOf(x);
int resID = getResources().getIdentifier(this_subject, "string", getPackageName());
Favorites_strings.add(getResources().getString(resID));
String x_string = String.valueOf(x);
Favorites_numbers.add(x_string);
}
}
lv = (ListView) findViewById(R.id.listViewf);
// Adding items to list view
adapter = new ArrayAdapter<String>(this, R.layout.row_layoutfavorites, R.id.populationf, Favorites_strings);
lv.setAdapter(adapter);
}