In my app I want two search between my saved records in SQLite database and in my table I have three fields: [ID] INTEGER NOT NULL PRIMARY KEY ON CONFLICT ABORT AUTOINCREMENT, [text] TEXT, [detail] text.
And from record 1 through 60 I open the data in first activity(ShowText) and from 60 through 120 in second activity(ShowPand).
Now in search class I have a list view for showing result and everything work well but when I click list item I don't know how to move to correct activity.
here my search class:
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
public class search extends ListActivity {
private database db;
private String[] Name;
private String[] Id;
private EditText edt_searchbox;
private RadioButton rdo_search_name;
private TextView status;
private Button btn_searching;
private RadioButton rdo_search_text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
db = new database(this);
edt_searchbox = (EditText) findViewById(R.id.edt_searchbox);
rdo_search_name = (RadioButton) findViewById(R.id.rdo_search_name);
rdo_search_text = (RadioButton) findViewById(R.id.rdo_search_text);
btn_searching = (Button) findViewById(R.id.btn_searching);
status = (TextView) findViewById(R.id.txt_status);
edt_searchbox.setTypeface(MainActivity.font);
status.setTypeface(MainActivity.font);
refresh(edt_searchbox.getText().toString(), "text");
btn_searching.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (rdo_search_name.isChecked()) {
refresh(edt_searchbox.getText().toString(), "text");
} else if (rdo_search_text.isChecked()) {
refresh(edt_searchbox.getText().toString(), "detail");
}
}
});
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
if(Id[position].equals("2")){
Intent in = new Intent(search.this, ShowText.class);
in.putExtra("name", Name[position]);
in.putExtra("page", Id[position]);
search.this.startActivity(in);
}else{
Intent in = new Intent(search.this, ShowPand.class);
in.putExtra("name", Name[position]);
in.putExtra("page", Id[position]);
search.this.startActivity(in);
}
}
class AA extends ArrayAdapter<String> {
public AA() {
super(search.this, R.layout.raw_seasone, Name);
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
LayoutInflater in = getLayoutInflater();
View row = in.inflate(R.layout.raw_seasonforsearch, parent, false);
// ----------------------------------------------------------
TextView name = (TextView) row.findViewById(R.id.name_season);
name.setText(Name[position]);
name.setTypeface(MainActivity.font);
// ----------------------------------------------------------------
return (row);
}
}
private void refresh(String text1, String field) {
db.open();
int s = db.count_search(text1, field);
if (edt_searchbox.getText().toString().equals("")) {
s = 0;
status.setText(" Please write your search word");
} else {
status.setText(" Your search have a " + s + " result ");
}
Name = new String[s];
Id = new String[s];
for (int i = 0; i < s; i++) {
if (field.equals("text")) {
Name[i] = db.search(i, 1, text1, field);
} else {
Name[i] = db.search(i, 2, text1, field);
}
Id[i] = db.search(i, 0, text1, field);
}
setListAdapter(new AA());
db.close();
}
}
In onListItemClick() method how tell that if Id[position]<=60 then open first activity and else open another one?
Aucun commentaire:
Enregistrer un commentaire