The situation is this: there is activity and it has a list (listview). Need to adjust the click handler so that when you click on the first item calls Activity2 showing the first fragment, and if you click on startup, the second element, then bring Activity2 showing the second fragment.
Sorry, My reputation < 10, because I cannot load image :( (Picture on other server: http://habrastorage.org/files/8d3/17b/e12/8d317be127484408aa7932154565f436.png )
My code:
public class Class extends Activity {
ArrayAdapter<String> adapter = null;
View emptyView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
getActionBar().hide();
ListView listView = (ListView) findViewById(R.id.ListView);
listView.setEmptyView(
emptyView = getLayoutInflater().inflate(R.layout.empty_view, null));
((ViewGroup)listView.getParent()).addView(emptyView);
fillListView();
listView.setAdapter(adapter);
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
if (((TextView) view).getText() == "Go1"){
} else
if (((TextView) view).getText() == "Go2"){
/* FragmentManager fragmentManager1 = getFragmentManager();
FragmentTransaction fragmentTransaction1 = fragmentManager1
.beginTransaction();
Intent Fragment1 = new Intent(Class.this, MainActivity.class);
startActivity(Fragment1);
Fr myFragment1 = new Fr();
myFragment1.setRetainInstance(true);
fragmentTransaction1.replace(R.id.container, myFragment1);
fragmentTransaction1.commit();
SearchActivity.this.finish();*/
}
if (((TextView) view).getText() == "Go3"){
}
}
});
EditText editFilter = (EditText) findViewById(R.id.edit_search);
editFilter.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
adapter.getFilter().filter(s.toString());
}
});
}
private void fillListView() {
List<String> catList = new ArrayList<String>();
catList.add("Go1");
catList.add("Go2");
catList.add("Go3");
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, catList);
}
}
0 comments:
Post a Comment