I'm starting to use SQLite in a project and would like some help on how to update
on a particular line, in this case, only one ID will be updated at a time.
Follow the codes:
View and where the update button is clicked:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
//recupera o estado da posição atual
final UserCommunity inviteUsers = usersList.get(position);
//Cria uma instancia do layout .. na view
View view = inflater.inflate(R.layout.item_invite_listview,null);
TextView txt_Nome = (TextView)view.findViewById(R.id.txt_nome_invite);
TextView txt_Email = (TextView)view.findViewById(R.id.txt_email_invite);
TextView txt_Distancia = (TextView)view.findViewById(R.id.txt_distancia_invite);
ImageButton btn_Share = (ImageButton)view.findViewById(R.id.img_invite);
txt_Nome.setText(inviteUsers.name);
txt_Email.setText(inviteUsers.email);
txt_Distancia.setText(Integer.toString(inviteUsers.distance));
btn_Share.setTag(position);
btn_Share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(AppController.getAppContext(),"Enviado para: "+inviteUsers.name,Toast.LENGTH_SHORT).show();
usersList.remove(position);
notifyDataSetChanged();
service.upddateDataBase(inviteUsers.id,true);
}
});
}
Service with method to update (how to do?):
public class InviteUsersService {
public void upddateDataBase(int id, boolean b) {
}
}
Bank code: (Field to be changed "invited BOOLEAN")
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_USERS_TABLE = "CREATE TABLE if not exists users ( " +
"id INTEGER PRIMARY KEY, " +
"name TEXT, "+
"email TEXT, "+
"company TEXT, "+
"photo_url TEXT, "+
"departure_time TEXT, "+
"arrival_time TEXT, "+
"address_lat DOUBLE,"+
"address_lng DOUBLE,"+
"invited BOOLEAN)";
// create books table
db.execSQL(CREATE_USERS_TABLE);
}