我有这个项目的arryalist,每个项目有小时字符串和分钟字符串。我可以将分钟分成数组,每分钟我想在clicklistener上添加textview。
我已经为listview实现了arrayadapter。一切都像预期的那样工作但只有一件事:我没有看到所有的文本视图,因为它们没有在显示器的末尾正确显示。
ListView行项目布局包含LinearLayout和textview以显示小时数。
listview适配器的代码:
public class DotazAdapter extends ArrayAdapter<Hours> {
private final ArrayList<Hours> model;
private final Context context;
public DotazAdapter(Context context, ArrayList<Hours> model) {
super(context, R.layout.hours_minutes,model);
this.model=model;
this.context=context;
// TODO Auto-generated constructor stub
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = null;
row = inflater.inflate(R.layout.hours_minutes, parent,false);
LinearLayout riadok = (LinearLayout)row.findViewById(R.id.horny);
TextView hodiny = (TextView)row.findViewById(R.id.hodinyBTV);
hodiny.setText(model.get(position).getHour());
String[] minuty = model.get(position).getMinutes().split(" ");
for(int i = 0; i<minuty.length;i++){
final TextView minutka = new TextView(context);
minutka.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
minutka.setText(minuty[i]+" ");
minutka.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "Stlacil si riadok "+position+ " a cislo v riadku :", Toast.LENGTH_SHORT).show();
}
});
riadok.addView(minutka, );
}
return row;
}
}
listitem的布局:
xml version=1.0 encoding=utf-8
LinearLayout xmlnsandroid=httpschemas.android.comapkresandroid
androidid=@+idhorny
androidlayout_width=match_parent
androidlayout_height=wrap_content
TextView
androidid=@+idhodinyBTV
androidlayout_width=wrap_content
androidlayout_height=wrap_content
androidlayout_marginRight=5dp
androidbackground=#F00C0C
androidtextColor=#FFFFFF
androidtextSize=18sp
LinearLayout