Метод onCreate():
Код: Выделить всё
currentStatusAdapter = new CurrentStatusAdapter(this, R.layout.current_status_listview_adapter, currentStatusData);
listViewCurrentStatus = (ListView)findViewById(R.id.listViewCurrentStatus);
listViewCurrentStatus.setBackgroundColor(getResources().getColor(R.color.black));
listViewCurrentStatus.setAdapter(currentStatusAdapter);
listViewCurrentStatus.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View v, final int position, long id){
Toast.makeText(WorkTableActivity.this, "position " + position +1, Toast.LENGTH_SHORT).show();
}
});
Код: Выделить всё
@Override
public View getView(int position, View convertView, ViewGroup parent){
row = convertView;
StatusHolder holder = null;
if(row==null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResoutceID, parent, false);
holder = new StatusHolder();
holder.textViewCurrentStatus = (TextView)row.findViewById(R.id.textViewCurrentStatus);
row.setTag(holder);
}
else
{
holder = (StatusHolder)row.getTag();
}
CurrentStatus currentStatus = currentStatusData.get(position);
holder.textViewCurrentStatus.setText(currentStatus.getCurrentStatus());
if(holder.textViewCurrentStatus.getText().charAt(0) == '0')
{
holder.textViewCurrentStatus.setBackgroundColor(R.color.white);
row.setBackgroundColor(R.color.white);
}
else
{
holder.textViewCurrentStatus.setBackgroundColor(R.color.black);
row.setBackgroundColor(R.color.black);
}
return row;
}
Код: Выделить всё
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="current status"
android:id="@+id/textViewCurrentStatus"
android:textColor="@color/green"/>
</LinearLayout>
Код: Выделить всё
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="1dp">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listViewCurrentStatus"
android:layout_weight="2"
android:layout_marginBottom="2dp"
android:divider="@color/green"
android:dividerHeight="2dp"/>