Android Programming Tutorials

(Romina) #1
The Restaurant Store

ViewGroup parent) {
LayoutInflater inflater=getLayoutInflater();
View row=inflater.inflate(R.layout.row, parent, false);
RestaurantHolder holder=new RestaurantHolder(row);

row.setTag(holder);

return(row);
}
}

static class RestaurantHolder {
private TextView name=null;
private TextView address=null;
private ImageView icon=null;
private View row=null;

RestaurantHolder(View row) {
this.row=row;

name=(TextView)row.findViewById(R.id.title);
address=(TextView)row.findViewById(R.id.address);
icon=(ImageView)row.findViewById(R.id.icon);
}

void populateFrom(Cursor c, RestaurantHelper helper) {
name.setText(helper.getName(c));
address.setText(helper.getAddress(c));

if (helper.getType(c).equals("sit_down")) {
icon.setImageResource(R.drawable.ball_red);
}
else if (helper.getType(c).equals("take_out")) {
icon.setImageResource(R.drawable.ball_yellow);
}
else {
icon.setImageResource(R.drawable.ball_green);
}
}
}
}

Similarly, here is a full implementation of RestaurantHelper that contains


the modifications from this tutorial:


package apt.tutorial;

import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteOpenHelper;

105
Free download pdf