I have got to add checkboxes in the firebase list adapter and set the adapter in the list view. I can click in the checkbox but when I click to the actual item from list view it doesn't send me to the detail activity to edit the list. If someone can point me to the right direction I really appreciate.
here is my BaseActivity
public class BaseActivity extends AppCompatActivity {
private ListView list;
protected SearchView searchView;
private String FirebaseID;
FirebaseUser mCurrentUser;
Firebase mDatabaseRef;
FirebaseListAdapter <Career> mAdapter;
CheckBox check ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Firebase.setAndroidContext(this);
mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
String current_uid = mCurrentUser.getUid();
mDatabaseRef = new Firebase(Constant.FIREBASE_URL).child("Users").child(current_uid).child("description");
// mDatabaseRef = FirebaseDatabase.getInstance().getReferenceFromUrl(Constant.FIREBASE_URL).child("description").child(current_uid);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
list = (ListView) findViewById(R.id.listView);
mAdapter = new FirebaseListAdapter<Career>(
this,
Career.class,
R.layout.career,mDatabaseRef
) {
@Override
protected void populateView(View view, Career career, int position) {
((TextView)view.findViewById(R.id.description)).setText(career.getDescription());
((TextView)view.findViewById(R.id.date)).setText(career.getDate());
((TextView)view.findViewById(R.id.title)).setText(career.getTitle());
}
};
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent inte = new Intent(getApplicationContext(), DetailActivity.class);
inte.putExtra("FirebaseID", mAdapter.getRef(position).getKey());
startActivityForResult(inte, 0);
}
});
registerForContextMenu(list);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView = (SearchView) menu.findItem(R.id.pesqContato).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(true);
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater m = getMenuInflater();
m.inflate(R.menu.menu_context, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
list.getAdapter();
FirebaseID = mAdapter.getRef(info.position).getKey().toString();
switch (item.getItemId()) {
case R.id.delete_item:
mDatabaseRef.child(FirebaseID).removeValue();
Toast.makeText(getApplicationContext(), "Contact Successfully deleted", Toast.LENGTH_SHORT).show();
return true;
}
return super.onContextItemSelected(item);
}
public void buildListView() {
list.setAdapter(mAdapter);
check = (CheckBox) findViewById(R.id.checkBox);
}
protected void buildSearchListView(String query) {
list.setAdapter(mAdapter);
}
}
Detail Activity
public class DetailActivity extends AppCompatActivity {
private Career career;
private String FirebaseID;
private EditText titleText;
private AutoCompleteTextView descriptionText;
private EditText dateText;
private Button button;
private DatabaseReference myDatabaseRef;
FirebaseUser mCurrentUser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Firebase.setAndroidContext(this);
mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
String current_uid = mCurrentUser.getUid();
myDatabaseRef = FirebaseDatabase.getInstance().getReference().child("Users").child(current_uid).child("description");
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Add your Goal");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
button = (Button) findViewById(R.id.button);
if (getIntent().hasExtra("FirebaseID")) {
FirebaseID = getIntent().getStringExtra("FirebaseID");
DatabaseReference refCareer = myDatabaseRef.child(FirebaseID);
refCareer.addValueEventListener(new com.google.firebase.database.ValueEventListener() {
@Override
public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) {
career = dataSnapshot.getValue(Career.class);
if (career != null) {
HashMap<String, Career> userMap = new HashMap<String, Career>();
titleText = (EditText) findViewById(R.id.editText3);
titleText.setText(career.getTitle());
descriptionText = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
descriptionText.setText(career.getDescription());
dateText = (EditText) findViewById(R.id.editText2);
dateText.setText(career.getDate());
userMap.put("description",career);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.detail, menu);
if (FirebaseID == null) {
MenuItem item = menu.findItem(R.id.delContact);
item.setVisible(false);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.saveContact:
save();
return true;
case R.id.delContact:
myDatabaseRef.child(FirebaseID).removeValue();
Toast.makeText(getApplicationContext(), "Contact successfully deleted", Toast.LENGTH_SHORT).show();
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void save() {
String description = ((AutoCompleteTextView) findViewById(R.id.autoCompleteTextView)).getText().toString();
String date = ((EditText) findViewById(R.id.editText2)).getText().toString();
String title = ((EditText) findViewById(R.id.editText3)).getText().toString();
if (career == null) {
career = new Career();
career.setTitle(title);
career.setDescription(description);
career.setDate(date);
myDatabaseRef.push().setValue(career);
Toast.makeText(this, "Contact successfully Added!!!", Toast.LENGTH_SHORT).show();
} else {
career.setTitle(title);
career.setDescription(description);
career.setDate(date);
myDatabaseRef.child(FirebaseID).setValue(career);
Toast.makeText(this, "Contact successfully Edited!!!", Toast.LENGTH_SHORT).show();
}
finish();
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26sp"
/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="19sp" />
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
/>
<CheckBox
android:id="@+id/checkBox"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_marginRight="2dp"
android:gravity="right|center" />
</LinearLayout>
And here where I have the list view
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeight"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/fab"
android:padding="16dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="58dp"
android:layout_height="54dp"
android:layout_gravity="bottom|end"
android:layout_marginBottom="25dp"
android:layout_marginRight="20dp"
android:focusable="true"
android:src="@android:drawable/ic_menu_edit"
app:elevation="24dp" />
</android.support.design.widget.CoordinatorLayout>