I get this error - Cannot resolve method 'onListItemClick(android.widget.ListView,android.view.View,int,long)'
I have tried using the onClickListener method but that does not work.
Please suggest.
Here is the code-
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;
ListView listview;
String[] pdflist;
File[] imagelist;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
listview.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(MainActivity.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
Use this instead:
yourListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
}
});
Replace this line from
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {
to
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener, OnItemClickListener {
and add following line in onCreate() method:
listview = (ListView) findViewById(R.id.listView1);
listview.setOnItemClickListener(this);
Related
my promblem is : i cant use animition for intent becuse this calss extend recyclerView adapter i know overridePendingTransition();but its dont work for tis class
It does not know => overridePendingTransition(R.layout.one,R.layout.two);
public class ListAdapterw extends RecyclerView.Adapter {
List<cardViewhomeinfo> sliders;
ImageLoader imageLoader=ImageLoader.getInstance();
public ListAdapterw(List<cardViewhomeinfo> sliders) {
this.sliders = sliders;
}
#Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater=LayoutInflater.from(parent.getContext());
View view=inflater.inflate(R.layout.recycleview_home,parent,false);
return new Holder(view);
}
#Override
public void onBindViewHolder(Holder holder, int position) {
holder.title.setText(sliders.get(position).getTitle());
holder.id=sliders.get(position).getId();
imageLoader.displayImage("http://wwwww"+sliders.get(position).getPicture(),holder.pic);
}
#Override
public int getItemCount() {
return sliders.size();
}
public class Holder extends RecyclerView.ViewHolder{
public TextView title;
public ImageView pic;
public String id="";
CardView cardView;
public Holder(final View itemView) {
super(itemView);
title=(TextView)itemView.findViewById(R.id.TitleCardView_home);
pic=(ImageView)itemView.findViewById(R.id.imageCardView_home);
cardView= (CardView) itemView.findViewById(R.id.cardView);
cardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(itemView.getContext(),subCat.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("id",id);
overridePendingTransition(R.layout.one,R.layout.two);
itemView.getContext().startActivity(intent);
}
});
}
}
}
and my activtity
public class Home extends Fragment {
View view;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view= inflater.inflate(R.layout.fragment_home, container, false);
JSON();
return view;
}
private void JSON() {
final RecyclerView recyclerView1 = (RecyclerView) view.findViewById(R.id.recycle_home);
StringRequest request=new StringRequest(Request.Method.GET, "", new Response.Listener<String>() {
#Override
public void onResponse(String s) {
try {
List<cardViewhomeinfo> sliders = new ArrayList<>();
JSONArray jsonArray=new JSONArray(s);
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonObject=jsonArray.getJSONObject(i);
cardViewhomeinfo slider = new cardViewhomeinfo();
slider.setTitle(jsonObject.getString("title"));
slider.setPicture(jsonObject.getString("pic"));
slider.setId(jsonObject.getString("id"));
sliders.add(slider);
}
ListAdapterw adapter = new ListAdapterw(sliders);
recyclerView1.setLayoutManager(new LinearLayoutManager(getActivity().getApplicationContext()));
recyclerView1.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError volleyError) {
dialog();
}
});
Volley.newRequestQueue(getActivity().getApplicationContext()).add(request);
}
private void dialog() {
Toast.makeText(getActivity().getApplicationContext(),"No INTENT",Toast.LENGTH_LONG).show();
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle("Home");
}
}
and subActivty
public class subCat extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub_cat);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Intent intent = getIntent();
final String idCat = intent.getStringExtra("id");
Toast.makeText(getApplicationContext(),idCat,Toast.LENGTH_LONG).show();}
Put your overridePendingTransition(R.layout.one,R.layout.two); code into the onCreate of the activity that you're going to when you click on cardView.
It should be something like this in your onCreate method of the activity:
public class subCat extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub_cat);
overridePendingTransition(R.layout.one,R.layout.two); //Put it here.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Intent intent = getIntent();
final String idCat = intent.getStringExtra("id");
Toast.makeText(getApplicationContext(),idCat,Toast.LENGTH_LONG).show();
}
Remove overridePendingTransition(R.layout.one,R.layout.two); this from the adapter class of your recycler view.
On the other hand,
overridePendingTransition(R.layout.one,R.layout.two);
it should be called
after finish();
or
after startActivity();
I am working on an app and I need to pass the contents of some textviews to a new activity, but I want to save the content I pass while the app is open so that the user can select more items from other activities and send them to the final checkout activity.
right now I have spinners which save the selection to a Textview
public class Americano extends AppCompatActivity {
// MyDBHandler dbHandler;
String result;
TextView tvSize;
Spinner spinner;
int mPos;
String mSelection;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_americano);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Spinner spinnerSize = (Spinner) findViewById(R.id.spinner_size);
AdapterView.OnItemSelectedListener listener = new myOnItemSelectedListener();
spinnerSize.setOnItemSelectedListener(listener);
Spinner spinnerSyrups = (Spinner) findViewById(R.id.spinner_syrups);
AdapterView.OnItemSelectedListener listenerSyrups = new myOnItemSelectedListener2();
spinnerSyrups.setOnItemSelectedListener(listenerSyrups);
Spinner spinnerTopping = (Spinner) findViewById(R.id.spinner_toppings);
AdapterView.OnItemSelectedListener listenerTopping = new myOnItemSelectedListener3();
spinnerTopping.setOnItemSelectedListener(listenerTopping);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
DBAdapter dbAdapter = new DBAdapter(view.getContext());
}
});
}
public class myOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
#Override
public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
Americano.this.mPos = pos;
Americano.this.mSelection = parent.getItemAtPosition(pos).toString();
TextView resultText = (TextView) findViewById(R.id.tvSize);
resultText.setText(Americano.this.mSelection);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
public class myOnItemSelectedListener2 implements AdapterView.OnItemSelectedListener {
#Override
public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
Americano.this.mPos = pos;
Americano.this.mSelection = parent.getItemAtPosition(pos).toString();
TextView resultText = (TextView) findViewById(R.id.tvSyrup);
resultText.setText(Americano.this.mSelection);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
public class myOnItemSelectedListener3 implements AdapterView.OnItemSelectedListener {
#Override
public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
Americano.this.mPos = pos;
Americano.this.mSelection = parent.getItemAtPosition(pos).toString();
TextView resultText = (TextView) findViewById(R.id.tvTopping);
resultText.setText(Americano.this.mSelection);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
I have more menu item classes exactly like this one
I want to pass the textview data to the checkout page. But save that data in that page until the user closes the app.
thanks
You can do it sending the information through an Intent.
In your listener you would go to another actvity like this:
Intent intent = new Intent(getActivity(), NewActivity.class);
intent.putExtra("RESULT_TEXT", resultText);
startActivity(intent);
And on the NewActivity you can get the information like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
Bundle bundle = getIntent().getExtras();
String resultText = bundle.getString("RESULT_TEXT", "");
}
Hope it helps.
When I want to get a name of list which I pressed, I get "com.example.oleksandr.dream.DB.DreamDetails#528f8a90". How can I get a String value from my list? The problem is in "the onItemClick" methode.
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private DBHelper mDbHelper = null;
private DreamDetails dreamDetails;
private ListView mListView;
private DrawerLayout drawerLayout;
private Toolbar mToolbar;
private Dao<DreamDetails, Integer> dreamDetailsDao;
private List<DreamDetails> dreamList;
private int selectedRecordPosition = -1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = (ListView) findViewById(R.id.listViewAllDreams);
try {
//Getting all Data from DB
dreamDetailsDao = getHelper().getDreamDetailsesDao();
dreamList = dreamDetailsDao.queryForAll();
// Set the header of the ListView
final LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view = inflater.inflate(R.layout.list_view, mListView, false);
mListView.addHeaderView(view);
// my own adapter!
mListView.setAdapter(new AdapterArrayDream(this,R.layout.list_view,dreamList,dreamDetailsDao));
mListView.setOnItemClickListener(this);
} catch (SQLException e) {
e.printStackTrace();
}
initToolbar();
initNavigationView();
FloatingActionButton myFab = (FloatingActionButton)findViewById(R.id.fab);
myFab.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, NewDream.class);
startActivity(intent);
}
});
}
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if(i > 0)
{
selectedRecordPosition = i - 1;
// final Intent intent = new Intent(this, ViewDream.class);
Log.i("TAAAAAAG", "onClick " + adapterView.getItemAtPosition(selectedRecordPosition));
// intent.putExtra("D", String.valueOf(adapterView.getItemAtPosition(selectedRecordPosition)));
// startActivity(intent);
}
}
private void initNavigationView() {
drawerLayout = (DrawerLayout) findViewById(R.id.drawlerLayout);
}
private void initToolbar() {
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setTitle(R.string.app_name);
mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
return false;
}
});
// mToolbar.inflateMenu(R.menu.menu);
}
// This is how, DatabaseHelper can be initialized for future use
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_list_dreams, menu);
return true;
}
private DBHelper getHelper() {
if (mDbHelper == null) {
mDbHelper = OpenHelperManager.getHelper(this, DBHelper.class);
}
return mDbHelper;
}
}
To create a query which looks up an account by name and password you would do the following:
QueryBuilder<Account, String> qb = accountDao.queryBuilder();
Where where = qb.where();
// the name field must be equal to "foo"
where.eq(Account.NAME_FIELD_NAME, "foo");
// and
where.and();
// the password field must be equal to "_secret"
where.eq(Account.PASSWORD_FIELD_NAME, "_secret");
PreparedQuery<Account, String> preparedQuery = qb.prepareQuery();
im new to this and have some problems, thanks for your help.
Situation:
I have a MainActivity and a second Activity called MainAddMedActivity. I get data from the second activity through an EditText and save it in the database. My intention is to display the data from the EditText in a ListView in the MainActivity by taking it from the database. How to do it the right way ?
Med:
#Table(name = "Med")
public class Med extends Model {
// Zähler für eindeutige IDs
private static long counter = 0;
#Column(name = "_id", unique = true, onUniqueConflict = Column.ConflictAction.REPLACE)
public long id;
#Column(name = "Description", index = true)
public String description;
public Med() {
super();
}
public Med(String message) {
super();
id = counter++;
description = message;
}
}
MedDAO:
public class MedDAO {
public static List<Med> getAll(String text) {
return new Select()
.from(Med.class)
.where("Description like ?", new String[]{'%' + text + '%'})
.orderBy("Description")
.limit(40)
.execute();
}
public static List<Med> getAll() {
return new Select()
.all()
.from(Med.class)
.execute();
}
public static List<Med> getOneItem(String text) {
return new Select()
.from(Med.class)
.where("Description = ?", text)
.execute();
}
public static void insertMed(String msg){
new Med(msg).save();
}
public static void remove(String text) {
new Delete().from(Med.class).where("Description = ?", text).execute();
}
}
MainActivity:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private ArrayAdapter<String> listAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), MainAddMedActivity.class);
startActivity(intent);
}
});
ListView mainListView = (ListView) findViewById(R.id.listView);
mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = listAdapter.getItem(position);
//Aus DB entfernen
MedDAO.remove(item);
//Aus Liste im Gui entfernen
listAdapter.remove(item);
Toast.makeText(getBaseContext(), item + "gelöscht", Toast.LENGTH_SHORT).show();
}
});
//TODO: ArrayAdapter bugt
//Adapter für die Liste erzeugen
listAdapter = new ArrayAdapter<String>(this, R.layout.single_row, R.id.listMedNrPart);
mainListView.setAdapter(listAdapter);
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onStart() {
super.onStart();
}
#Override
public void onStop() {
super.onStop();
}
#Override
public void onResume() {
super.onResume();
// MedDAO.getLatestItem();
/*int max = listAdapter.getCount();
int i = 0;
while (i < max){
Log.d("MainActivity", listAdapter.getItem(i));
i++;
}*/
// listAdapter.add(MedDAO.getLatestItem().toString());
}
}
MainAddMedActivity:
public class MainAddMedActivity extends AppCompatActivity {
private EditText txtSearchMedicament;
private EditText txtNumberMedicament;
private TextView txtAlarmPrompt;
private TimePickerDialog timePickerDialog;
private Switch switchReminder;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_add_med);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
EditText description = (EditText) findViewById(R.id.txtSearchMedicament);
String text = description.getText().toString();
**//SAVE IN DATABASE**
MedDAO.insertMed(text);
//TODO: Close Activity
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
this.txtSearchMedicament = (EditText) findViewById(R.id.txtSearchMedicament);
this.txtNumberMedicament = (EditText) findViewById(R.id.txtNumberMedicament);
this.txtAlarmPrompt = (TextView) findViewById(R.id.txtAlarmPrompt);
this.switchReminder = (Switch) findViewById(R.id.switchReminder);
switchReminder.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cancelSwitch();
}
}
});
A Content Provider could be used. It takes a good amount of code to implement but it binds your database to your view.
Here is an example of a Content Provider I have implemented in the past.
You construct a ContentValue object (basically a set of values to mimic a database row) for your database keys and set your new data there. You then use getContentResolver() to insert the ContentValue into your Content Provider, which in turn updates your database with your new data.
ContentValues values = new ContentValues();
values.put(DatabaseHelper.KEY_VENUE_NAME, store.getName());
values.put(DatabaseHelper.KEY_VENUE_CITY, store.getCity());
values.put(DatabaseHelper.KEY_VENUE_STATE, store.getState());
//insert row
context.getContentResolver().insert(Uri.parse(ContentProvider.base_CONTENT_URI + index), values);
Here's an example of the Content Provider Class (too much code for here) which implements the logic for inserting, deleting, querying, editing, and constructing URI paths to your database.
You can then set up and use a Cursor, which iterates through your data source, to access the data from your Content Provider, more specifically you can extend CursorAdapter to directly bind your views to database queries. Here is what one looks like:
public class StoreCursorAdapter extends SimpleCursorAdapter {
private static final String TAG = "VenueCursorAdapter";
DatabaseHelper databaseHelper;
private Context context;
private int layout;
private int selection; //MapsActivity.getStoreSelection();
public StoreCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
databaseHelper = DatabaseHelper.getInstance(context);
this.context = context;
this.layout = layout;
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(layout, parent, false);
return v;
}
#Override
public void bindView(View v, Context context, Cursor c) {
selection = ((MapsActivity) context).getStoreSelection();
int position = c.getPosition();
int nameColumn = c.getColumnIndex(DatabaseHelper.KEY_VENUE_NAME);
String name = c.getString(nameColumn);
TextView nameText = (TextView) v.findViewById(R.id.nameTextView);
TextView ratingText = (TextView) v.findViewById(R.id.ratingTextView);
if(nameText != null && ratingText != null) {
nameText.setText(name);
}
}
}
I´m trying to udate a ListView in a Fragment the only way it actually will work is if I instanciate the fragment new. adpter.notifyDataSetChanged() is not working? Whay not? Here the Code an Activity and the Fragment:
public class TimerList extends Activity{
private DataSource datasource;
TimerListFragment timerfragment;
IntervalListFragment intervalfragment;
public List<TimerObject> values;
public String name;
public String intervals;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.interval_fragment_container);
datasource = new DataSource(this);
datasource.open();
values = datasource.getAllComments();
if (savedInstanceState == null) {
Toast.makeText(getApplicationContext(), "MADE NEW FRAGMENTS", Toast.LENGTH_SHORT).show();
timerfragment = new TimerListFragment();
intervalfragment = new IntervalListFragment();
}
}
public void delete(Long position){
TimerObject timerobject = datasource.getTimerObject(position);
datasource.deleteComment(timerobject);
values = datasource.getAllComments();
}
#Override
protected void onStart() {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, timerfragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
super.onStart();
}
And my Fragment :
public class TimerListFragment extends ListFragment {
List<TimerObject> values ;
Activity a;
ArrayAdapter<TimerObject> adapter;
ListView lv;
#Override
public void onCreate(Bundle savedInstanceState) {
setHasOptionsMenu(true);
values = ((TimerList)getActivity()).getValues();
setBar();
adapter = new ArrayAdapter<TimerObject>(getActivity(), android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
super.onCreate(savedInstanceState);
}
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
((TimerList)getActivity()).play(Long.valueOf(position));
super.onListItemClick(l, v, position, id);
}
public void setBar(){
ActionBar actionbar = getActivity().getActionBar();
actionbar.setTitle("Timer List");
}
public void update(){
setBar();
Toast.makeText(getActivity(), "UPDATE", Toast.LENGTH_LONG).show();
values = ((TimerList)getActivity()).getValues();
adapter.notifyDataSetChanged();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.interval_timer_list,
container, false);
return view;
}
#Override
public void onStart() {
update();
lv = getListView();
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
final TimerObject selected = adapter.getItem(position);
final Dialog d = new Dialog(getActivity());
d.setContentView(R.layout.interval_deletetimer_dialog);
d.setTitle("Delete " + selected.getComment() + "?" );
ImageButton delete = (ImageButton) d.findViewById(R.id.delete);
delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
((TimerList)getActivity()).delete(Long.valueOf(selected.getId()));
update();
}
});
d.show();
return true;
}
});
super.onStart();
}
I tried to do something similar, and I solved this problem by simply redoing the fragment transaction.
In your case, you could accomplish this within your onListItemClick() method.
you could copy this:
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, timerfragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
into your onListItemClick() method in your fragment
This resets the fragment. Unfortunately, this would also set your list to null. A way around this would be to make the values list a private static variable of the TimerListFragment class. That way, any changes made to the list will remain 'saved', and when you reload your fragment, it will be populated with the newly updated list.
hope this helps