"unable to find explicit activity" error - java

I'm new in android and I just try to use this code and show the save data on database in listView. but when i press the button say unfortunately has stopped. please help me.
MainActivity Class
package com.example.employeedetailsnew;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.*;
public class MainActivity extends Activity{
private EditText nme = null;
private EditText num = null;
private EmployeeDatabase empObj;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nme = (EditText) findViewById(R.id.name);
num = (EditText) findViewById(R.id.ageemp);
Button btnShowData = (Button) findViewById(R.id.button2);
btnShowData.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
onSaveClick();
}
});
}
public void onButtonClicked(View view) {
if (nme.length()!=0 && num.length()!=0){
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd:MMMM:yyyy HH:mm:ss a");
String strDate = sdf.format(c.getTime());
String varName = nme.getText().toString();
String varAge = num.getText().toString();
empObj = new EmployeeDatabase(getApplicationContext());
empObj.insert(varName,varAge,strDate);
AlertDialog alertDialog = null;
alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle(getResources().getString(R.string.Message));
alertDialog.setMessage(getResources().getString(R.string.You_have_been_Registered));
alertDialog.setCancelable(true);
alertDialog.show();
nme.setText("");
num.setText("");
}else{
Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.Empty_Item),
Toast.LENGTH_SHORT);
toast.show();
}
}
public void onSaveClick(){
Intent intent = new Intent(this, ShowData.class);
startActivity(intent);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Detail Class
package com.example.employeedetailsnew;
public class DetailClass {
private String name;
private String age;
private String time;
public String getName() {
return name;
}
public String getAge() {
return age;
}
public String getTime() {
return time;
}
}
MyAdaptor Class
package com.example.employeedetailsnew;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
public class MyAdapter extends CursorAdapter {
public MyAdapter(Context context, Cursor c) {
super(context, c);
}
#Override
public int getCount() {
return 0;
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int index, View view, ViewGroup parent) {
if (view == null)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
view = inflater.inflate(R.layout.shows_view, parent, false);
}
ArrayList times = null;
DetailClass empDtl = (DetailClass) times.get(index);
TextView nameTextView = (TextView) view.findViewById(R.id.name1);
nameTextView.setText(empDtl.getName());
TextView ageTextView = (TextView) view.findViewById(R.id.age2);
ageTextView.setText(empDtl.getAge());
TextView timeTextView = (TextView) view.findViewById(R.id.time3);
timeTextView.setText((CharSequence) empDtl.getTime());
return view;
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
TextView nameTextView = (TextView) view.findViewById(R.id.name1);
nameTextView.setText(cursor.getString(cursor.getColumnIndex("name")));
TextView ageTextView = (TextView) view.findViewById(R.id.name1);
ageTextView.setText(cursor.getString(cursor.getColumnIndex("age")));
TextView timeTextView = (TextView) view.findViewById(R.id.name1);
timeTextView.setText(cursor.getString(cursor.getColumnIndex("time")));
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from (parent.getContext());
View view = inflater.inflate(R.layout.shows_list, parent, false);
return view;
}
}
MyDataBase Class
package com.example.employeedetailsnew;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
class EmployeeDatabase extends SQLiteOpenHelper{
EmployeeDatabase (Context context) {
super(context, "empdb.db", null,3);
}
#Override
public void onCreate(SQLiteDatabase database)
{
database.execSQL("create table employee" + "(name TEXT , age TEXT, time TEXT)");
}
#Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion)
{
database.execSQL("DROP TABLE IF EXISTS EMPLOYEEDETAILNEW");
onCreate(database);
}
public Cursor getDetails()
{
SQLiteDatabase db = getReadableDatabase();
return db.rawQuery("select rowid _id,name, age,time from employeedetailnew", null);
}
public void insert(String name, String age, String time)
{
long rowId = 0;
try{
SQLiteDatabase db = getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("name", name);
contentValues.put("age", age);
contentValues.put("time", time);
rowId = db.insert("employeedetailnew", null, contentValues);
}catch(Exception e){
e.printStackTrace();
}
finally{
System.out.println("The rowId is "+rowId);
System.out.println("Name is "+name);
System.out.println("Age is "+age);
System.out.println("Time is "+time);
}
}
public boolean deleteTitle(String name)
{
SQLiteDatabase db = getWritableDatabase();
return db.delete("employeedetailnew", name + "=" + name, null) > 0;
}
}
ShowData Class
package com.example.employeedetailsnew;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
public class ShowData extends ListActivity
{
private EmployeeDatabase databaseHelper;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shows_list);
EmployeeDatabase empClick = new EmployeeDatabase(getApplicationContext());
Cursor cursor = empClick.getDetails();
if (cursor.moveToFirst())
{
do
{
String name = cursor.getString(1);
String notes = cursor.getString(2);
String time = cursor.getString(3);
} while (cursor.moveToNext());
}
if (!cursor.isClosed())
{
cursor.close();
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.employeedetailsnew.MainActivity$PlaceholderFragment" >
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/empname"
android:layout_below="#+id/empname"
android:layout_marginTop="19dp"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/sub"
android:layout_below="#+id/sub"
android:layout_marginTop="24dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1" />
<TextView
android:id="#+id/empname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="46dp"
android:layout_marginTop="27dp"
android:text="#string/name" />
<TextView
android:id="#+id/age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/name"
android:layout_below="#+id/name"
android:layout_marginTop="16dp"
android:text="#string/age" />
<EditText
android:id="#+id/ageemp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/age"
android:layout_below="#+id/age"
android:ems="10"
android:inputType="numberSigned" />
<Button
android:id="#+id/sub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/button3"
android:layout_centerVertical="true"
android:onClick="onButtonClicked"
android:text="#string/sub" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView1"
android:layout_centerHorizontal="true"
android:text="#string/show_data" />
</RelativeLayout>
shows_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
shows_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/name1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/age2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/time3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
and that's my logcat
08-16 11:52:08.427 28242-28242/com.example.employeedetailsnew E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.employeedetailsnew/com.example.employeedetailsnew.ShowData}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3390)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.app.Activity.startActivity(Activity.java:3587)
at android.app.Activity.startActivity(Activity.java:3555)
at com.example.employeedetailsnew.MainActivity.onSaveClick(MainActivity.java:60)
at com.example.employeedetailsnew.MainActivity$1.onClick(MainActivity.java:30)
at android.view.View.performClick(View.java:4421)
at android.view.View$PerformClick.run(View.java:17903)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)

add ShowData Activity in manifest.xml
<activity
android:name=".ShowDatata"/>

Related

keep getting error "Unresolved reference: valueOf"

In in the notes portion of my app i get the error "Unresolved reference: valueOf" in my EquipmentTrackerAllnotes.kt file.
the way my app operates is when you open the app initially it opens up to the dashboard the main home screen, then there is a navigation drawer on the side. One of the fragments in the navigation drawer is my "EquipmentTracker" aka the area where you can make notes of equipment the user may have. In side there you can add notes, delete and edit.
I'm open ears to any recommendations on possible changes i should make as well. But for now my main focus is fixing this error listed above.
EquipmentTracker.kt
package com.example.mechanicsapp
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.example.mechanicsapp.Model.noteModel
import com.example.mechanicsapp.database.MySqliteHelper
import com.example.mechanicsapp.databinding.FragmentEquipmentTrackerBinding
class EquipmentTracker : Fragment() {
private var _binding: FragmentEquipmentTrackerBinding? = null
private val binding get() = _binding!!
var intent = Intent(requireContext(), EquipmentTracker::class.java)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
//return inflater.inflate(R.layout.sign_in_fragment, container, false)
// Inflate the layout for this fragment
_binding = FragmentEquipmentTrackerBinding.inflate(inflater, container, false)
binding.root
val helper = MySqliteHelper(requireContext())
binding.btnDisplay.setOnClickListener(View.OnClickListener {
intent = Intent(activity, FragmentEquipmentTrackerBinding::class.java)
startActivity(intent)
return#OnClickListener
})
binding.btnSave.setOnClickListener(View.OnClickListener {
val model = noteModel()
model.bumpernumber = binding.bumpernumber.text.toString()
model.description = binding.description.text.toString()
model.nsn = binding.nsn.text.toString()
model.serialnumber = binding.serialnumber.text.toString()
model.date = binding.date.text.toString()
if (model.bumpernumber.isEmpty()) {
binding.bumpernumber.error = "Enter bumper number"
return#OnClickListener
}
if (model.description.isEmpty()) {
binding.description.error = "Enter description"
return#OnClickListener
}
if (model.nsn.isEmpty()) {
binding.nsn.error = "Enter nsn"
return#OnClickListener
}
if (model.serialnumber.isEmpty()) {
binding.serialnumber.error = "Enter serial number"
return#OnClickListener
}
if (model.date.isEmpty()) {
binding.date.error = "Enter date"
return#OnClickListener
}
val r = helper.saveNote(model)
if (r) {
Toast.makeText(context, "note is saved", Toast.LENGTH_SHORT)
.show()
} else {
Toast.makeText(context, "some thing want wrong", Toast.LENGTH_SHORT)
.show()
}
})
return binding.root
}
}
EquipmentTrackerAllnotes.kt
package com.example.mechanicsapp
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import com.example.mechanicsapp.Model.noteModel
import com.example.mechanicsapp.adapter.NoteAdapter
import com.example.mechanicsapp.database.MySqliteHelper
import com.example.mechanicsapp.databinding.ActivityEquipmentTrackerAllnotesBinding
#Suppress("NAME_SHADOWING")
class EquipmentTrackerAllnotes : AppCompatActivity() {
private var adapter: NoteAdapter? = null
private var binding: ActivityEquipmentTrackerAllnotesBinding? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityEquipmentTrackerAllnotesBinding.inflate(layoutInflater)
setContentView(binding!!.root)
fetchNotes()
}
private fun fetchNotes() {
val helper = MySqliteHelper(this)
adapter = NoteAdapter(this, helper.allNotes)
adapter!!.setOnNoteItemClickListener(object : NoteAdapter.OnNoteItemClickListener {
override
fun Onclick(model: noteModel) {
val builder = AlertDialog.Builder(this#EquipmentTrackerAllnotes)
builder.setTitle("Important")
builder.setMessage("Are your sure?")
builder.setPositiveButton("Yes" ) {
dialogInterface, _ ->
val helper = MySqliteHelper(this#EquipmentTrackerAllnotes)
val check = helper.delNoteById(String.valueOf(model.id))
if (check) {
fetchNotes()
Toast.makeText(this#EquipmentTrackerAllnotes, "Deleted", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(
this#EquipmentTrackerAllnotes,
"something went wrong",
Toast.LENGTH_SHORT
).show()
}
dialogInterface.dismiss()
}.setNegativeButton(
"No"
) { dialogInterface, _ -> dialogInterface.dismiss() }
builder.create().show()
}
override fun OnEdit(model: noteModel) {
val builder = AlertDialog.Builder(this#EquipmentTrackerAllnotes)
val view: View = LayoutInflater.from(this#EquipmentTrackerAllnotes)
.inflate(R.layout.edit_note, null, false)
val bm = view.findViewById<EditText>(R.id.bumpernumber)
val des = view.findViewById<EditText>(R.id.description)
val nsn = view.findViewById<EditText>(R.id.nsn)
val sn = view.findViewById<EditText>(R.id.serialnumber)
val date = view.findViewById<EditText>(R.id.date)
val btnUpdate = view.findViewById<Button>(R.id.btnUpdate)
bm.setText(model.bumpernumber)
des.setText(model.description)
nsn.setText(model.nsn)
sn.setText(model.serialnumber)
date.setText(model.date)
builder.setView(view)
val alertDialog = builder.create()
btnUpdate.setOnClickListener {
val model1 = noteModel()
model1.id = model.id
model1.bumpernumber = bm.text.toString()
model1.description = des.text.toString()
model1.nsn = nsn.text.toString()
model1.serialnumber = sn.text.toString()
model1.date = date.text.toString()
updateNote(model1)
alertDialog.dismiss()
}
alertDialog.show()
}
})
this.binding?.recyclerView?.setHasFixedSize(true)
this.binding?.recyclerView?.layoutManager = LinearLayoutManager(this)
this.binding?.recyclerView?.adapter = adapter
}
private fun updateNote(model: noteModel) {
val helper = MySqliteHelper(this#EquipmentTrackerAllnotes)
val check = helper.updateNoteById(model)
if (check) {
fetchNotes()
Toast.makeText(this, "Updated", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "something went wrong", Toast.LENGTH_SHORT).show()
}
}
}
in my adapter folder I have NoteAdapter.java
NoteAdapter.java
package com.example.mechanicsapp.adapter;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.mechanicsapp.Model.noteModel;
import com.example.mechanicsapp.R;
import com.example.mechanicsapp.database.MySqliteHelper;
import java.util.List;
public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.viewHolder> {
List<noteModel> list;
Activity activity;
OnNoteItemClickListener listener;
public NoteAdapter(Activity activity,List<noteModel> list) {
this.list=list;
this.activity=activity;
}
#NonNull
#Override
public viewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.row_note,null,false);
return new viewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull viewHolder holder, int position) {
noteModel model=list.get(position);
holder.bumpernumber.setText(model.getBumpernumber());
holder.description.setText(model.getDescription());
holder.nsn.setText(model.getNsn());
holder.serialnumber.setText(model.getSerialnumber());
holder.date.setText(model.getDate());
holder.more.setOnClickListener(view -> {
PopupMenu menu=new PopupMenu(activity,holder.more);
menu.getMenuInflater().inflate(R.menu.more_menu,menu.getMenu());
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.edit:
listener.OnEdit(model);
break;
case R.id.delete:
listener.Onclick(model);
break;
}
return false;
}
});
menu.show();
});
}
#Override
public int getItemCount() {
return list.size();
}
public static class viewHolder extends RecyclerView.ViewHolder{
TextView bumpernumber,description,nsn,serialnumber,date;
ImageView more;
public viewHolder(#NonNull View itemView) {
super(itemView);
bumpernumber=itemView.findViewById(R.id.bumpernumber);
description=itemView.findViewById(R.id.description);
nsn=itemView.findViewById(R.id.nsn);
serialnumber=itemView.findViewById(R.id.serialnumber);
date=itemView.findViewById(R.id.date);
more=itemView.findViewById(R.id.more);
}
}
public interface OnNoteItemClickListener{
void Onclick(noteModel model);
void OnEdit(noteModel model);
}
public void setOnNoteItemClickListener(OnNoteItemClickListener listener){
this.listener=listener;
}
}
in my database folder i have MySqliteHelper.java & TableSchema.java
MySqliteHelper.java
package com.example.mechanicsapp.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
import com.google.android.material.tabs.TabLayout;
import com.example.mechanicsapp.Model.noteModel;
import java.util.ArrayList;
import java.util.List;
public class MySqliteHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME="note.db";
private static final int VERSION=1;
public MySqliteHelper(#Nullable Context context) {
super(context, DATABASE_NAME, null, VERSION);
}
#Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String table1="create table "+TableSchema.note.TABLE_NAME+"("+TableSchema.note.ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+TableSchema.note.BUMPERNUMBER+" TEXT, "+TableSchema.note.DESCRIPTION+" TEXT,"+TableSchema.note.NSN+" TEXT,"+TableSchema.note.SERIALNUMBER+" TEXT, "+TableSchema.note.DATE+" TEXT );";
sqLiteDatabase.execSQL(table1);
}
public boolean saveNote(noteModel model){
SQLiteDatabase database=this.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(TableSchema.note.BUMPERNUMBER,model.getBumpernumber());
cv.put(TableSchema.note.DESCRIPTION,model.getDescription());
cv.put(TableSchema.note.NSN,model.getNsn());
cv.put(TableSchema.note.SERIALNUMBER,model.getSerialnumber());
cv.put(TableSchema.note.DATE,model.getDate());
long id= database.insert(TableSchema.note.TABLE_NAME,null,cv);
return id != -1;
}
public List<noteModel> getAllNotes(){
SQLiteDatabase database= this.getReadableDatabase();
String[] cols={TableSchema.note.ID,TableSchema.note.BUMPERNUMBER,TableSchema.note.DESCRIPTION,TableSchema.note.NSN,TableSchema.note.SERIALNUMBER,TableSchema.note.DATE};
Cursor cursor=database.query(TableSchema.note.TABLE_NAME,cols,null,null,null,null,TableSchema.note.ID+" DESC");
ArrayList<noteModel> list=new ArrayList<>();
while (cursor.moveToNext()){
noteModel model=new noteModel();
model.setId(cursor.getInt(cursor.getColumnIndexOrThrow(TableSchema.note.ID)));
model.setBumpernumber(cursor.getString(cursor.getColumnIndexOrThrow(TableSchema.note.BUMPERNUMBER)));
model.setDescription(cursor.getString(cursor.getColumnIndexOrThrow(TableSchema.note.DESCRIPTION)));
model.setNsn(cursor.getString(cursor.getColumnIndexOrThrow(TableSchema.note.NSN)));
model.setSerialnumber(cursor.getString(cursor.getColumnIndexOrThrow(TableSchema.note.SERIALNUMBER)));
model.setDate(cursor.getString(cursor.getColumnIndexOrThrow(TableSchema.note.DATE)));
list.add(model);
}
cursor.close();
database.close();
return list;
}
public boolean delNoteById(String id){
SQLiteDatabase database=this.getWritableDatabase();
int d_id=database.delete(TableSchema.note.TABLE_NAME,TableSchema.note.ID+"=?",new String[]{id});
if (d_id==-1){
database.close();
return false;
}
database.close();
return true;
}
public boolean updateNoteById(noteModel model){
SQLiteDatabase database=this.getWritableDatabase();
ContentValues values=new ContentValues();
values.put(TableSchema.note.BUMPERNUMBER,model.getBumpernumber());
values.put(TableSchema.note.DESCRIPTION,model.getDescription());
values.put(TableSchema.note.NSN,model.getNsn());
values.put(TableSchema.note.SERIALNUMBER,model.getSerialnumber());
values.put(TableSchema.note.DATE,model.getDate());
int u_id=database.update(TableSchema.note.TABLE_NAME,values,TableSchema.note.ID+"=?",new String[]{String.valueOf(model.getId())});
if (u_id==-1){
database.close();
return false;
}
database.close();
return true;
}
#Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
if (i<i1){
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS "+TableSchema.note.TABLE_NAME);
}
}
}
TableSchema.java
package com.example.mechanicsapp.database;
public class TableSchema {
public static class note{
public static final String TABLE_NAME="tbl_note";
public static final String ID="id";
public static final String BUMPERNUMBER="bumpernumber";
public static final String DESCRIPTION="description";
public static final String NSN="nsn";
public static final String SERIALNUMBER="serialnumber";
public static final String DATE="date";
}
}
in my Model folder i have noteModel.java
//noteModel.java
package com.example.mechanicsapp.Model;
public class noteModel {
private int id;
private String bumpernumber;
private String description;
private String nsn;
private String serialnumber;
private String date;
public noteModel() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBumpernumber() {
return bumpernumber;
}
public void setBumpernumber(String bumpernumber) {
this.bumpernumber = bumpernumber;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getNsn() {
return nsn;
}
public void setNsn(String nsn) {
this.nsn = nsn;
}
public String getSerialnumber() {
return serialnumber;
}
public void setSerialnumber(String serialnumber) {
this.serialnumber = serialnumber;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
fragment_equipment_tracker.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EquipmentTracker">
<LinearLayout
android:layout_centerInParent="true"
android:padding="10dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/bumpernumber"
android:hint="Bumper Number"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/description"
android:hint="Enter description"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/nsn"
android:hint="Enter nsn"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/serialnumber"
android:hint="Enter serial number"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/date"
android:hint="Enter date"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnSave"
android:text="Save"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnDisplay"
android:text="Display"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
activity_equipment_tracker_allnotes.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EquipmentTrackerAllnotes">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
edit_note.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EquipmentTracker">
<LinearLayout
android:padding="10dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/bumpernumber"
android:hint="Bumper Number"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/description"
android:hint="Enter description"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/nsn"
android:hint="Enter nsn"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/serialnumber"
android:hint="Enter serial number"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/date"
android:hint="Enter date"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnUpdate"
android:text="Update"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
//row_note.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_margin="10dp"
android:padding="10dp"
cardElevation="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/bumpernumber"
android:textSize="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/nsn"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/serialnumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/date"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<ImageView
android:id="#+id/more"
android:src="#drawable/baseline_more_vert_24"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
more_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/edit" android:title="edit"/>
<item android:id="#+id/delete" android:title="Delete"/>
</menu>

listview onitemclicklistener not working using in activity

Hello friend i have custom listview using arrayadopter in my activity i am using listview on item click listner but problem is that its not working please help me here is my code the tost message which i used in my onitem click listner in my activity is not working what problem is here please tell
my custom layout for listview code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_margin="0dp"
android:padding="0dp"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="28dp"
android:layout_height="28dp"
android:id="#+id/versenumber"
android:text="1"
android:background="#drawable/roundedbutton"/>
<TextView
android:layout_width="match_parent"
android:id="#+id/verse"
android:layout_gravity="center|top"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="#color/darkcolor"
android:textSize="20sp"
android:text="#string/versedisplay"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="top"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/speakverse"
android:layout_width="28dp"
android:layout_marginTop="10dp"
android:layout_height="28dp"
fab:srcCompat="#drawable/speak" />
<ImageView
android:layout_width="28dp"
android:layout_height="28dp"
android:id="#+id/share"
android:paddingTop="-10dp"
android:layout_marginTop="10dp"
android:src="#drawable/ic_share_black_24dp"/>
<ToggleButton
android:id="#+id/adbookmark"
android:layout_marginTop="10dp"
android:layout_width="27dp"
android:layout_height="28dp"
android:layout_gravity="right"
android:background="#drawable/toggle_selector"
android:textOff=""
android:textOn="" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:textAlignment="center"
android:layout_gravity="top"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ALLVERSE">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorAccent"
app:popupTheme="#style/AppTheme.PopupOverlay">
<TextView
android:id="#+id/bookname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="20sp"
android:textColor="#ffffff"
android:textStyle="bold"
android:text="ALL VERESE" />
</android.support.v7.widget.Toolbar>
<ListView
android:layout_below="#+id/toolbar"
android:id="#+id/mylistview"
android:divider="#null"
android:dividerHeight="3dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ALLVERSE">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorAccent"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/allversecontent" />
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/allverseappbar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
package bible.swordof.God;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import es.dmoral.toasty.Toasty;
public class ALLVERSE extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private ListView listView;
private ArrayList<String>versenumber;
private ArrayList<String>verselist;
private ArrayList<String>id;
private ArrayList<String>refernce;
private DatabaseHelper mDBHelper;
private SQLiteDatabase mDb;
private int booknumber;
private int chapternumber;
private String bookname;
private TextView booknametitle;
private FullverseAdopter adopter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_allverse);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
booknametitle=findViewById(R.id.bookname);
Intent mIntent = getIntent();
booknumber = mIntent.getIntExtra("Boooknumber",0);
chapternumber= mIntent.getIntExtra("Chapternumber", 0);
bookname=mIntent.getStringExtra("Bookname");
booknametitle.setText(bookname.toString() +" "+ chapternumber);
//Toast.makeText(this, ""+bookname, Toast.LENGTH_SHORT).show();
setSupportActionBar(toolbar);
toolbar.setTitle("ALL VERSE");
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
setData();
listView =findViewById(R.id.list);
adopter=new FullverseAdopter(this,R.layout.versedisplayrow,versenumber,verselist,refernce,id);
listView.setAdapter(adopter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(ALLVERSE.this, "LIFE RUNS ON CODE", Toast.LENGTH_SHORT).show();
}
});
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle arrow click here
if (item.getItemId() == android.R.id.home) {
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
private void setData() {
versenumber=new ArrayList<>();
verselist=new ArrayList<>();
refernce=new ArrayList<>();
id=new ArrayList<>();
mDBHelper = new DatabaseHelper(this);
mDb = mDBHelper.getReadableDatabase();
Cursor cursor = mDb.rawQuery("SELECT id, v, t from t_kjv where b="+booknumber+" AND c="+chapternumber+";", new String[]{});
if(cursor!=null && cursor.getCount() > 0)
{ if (cursor.moveToFirst())
{
do {
id.add(cursor.getString(0));
versenumber.add(cursor.getString(1));
verselist.add(cursor.getString(2));
refernce.add(bookname+" "+chapternumber);
}
while (cursor.moveToNext());
}
}
}
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
Fragment fragment;
int id = item.getItemId();
if (id == R.id.home) {
Intent intent=new Intent(this,MainActivity.class);
startActivity(intent);
} else if (id == R.id.favoruite)
{ Intent intent=new Intent(this,Favourite.class);
startActivity(intent);
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
My adopter customadopter class:
package bible.swordof.God;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.opengl.Visibility;
import android.preference.PreferenceManager;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import es.dmoral.toasty.Toasty;
import petrov.kristiyan.colorpicker.ColorPicker;
import static android.content.Context.MODE_PRIVATE;
import static android.database.sqlite.SQLiteDatabase.CONFLICT_NONE;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.V;
import static android.support.constraint.Constraints.TAG;
import static android.support.v4.content.ContextCompat.createDeviceProtectedStorageContext;
import static android.support.v4.content.ContextCompat.startActivity;
public class FullverseAdopter extends ArrayAdapter<String> {
private ALLVERSE activity;
private List<String> versenumber;
private List<String>verseid;
private List<String> verselist;
private List<String> refernce;
TextToSpeech textToSpeech;
private DatabaseHelper mDBHelper;
private SQLiteDatabase mDb;
private boolean ischeckd;
String My_PREF="MY_PREF";
public String ex="switch";
//check for availabe language
int result;
public FullverseAdopter(ALLVERSE context, int resource, List<String> versenumber, List<String> verselist, List<String> refernce, List<String>verseid) {
super(context, resource, versenumber);
this.activity = context;
this.versenumber = versenumber;
this.verselist = verselist;
this.refernce = refernce;
this.verseid=verseid;
}
#Override
public int getCount() {
return versenumber.size();
}
#Override
public String getItem(int position) {
return versenumber.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, final ViewGroup parent) {
final ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
// If holder not exist then locate all view from UI file.
if (convertView == null) {
// inflate UI from XML file
convertView = inflater.inflate(R.layout.versedisplayrow, parent, false);
// get all UI view
holder = new ViewHolder(convertView);
// set tag for holder
holder.versenumber = (TextView) convertView.findViewById(R.id.versenumber);
holder.verselist = (TextView) convertView.findViewById(R.id.verse);
holder.addfavoruite=(ToggleButton)convertView.findViewById(R.id.adbookmark);
convertView.setTag(holder);
} else {
// if holder created, get tag from view
holder = (ViewHolder) convertView.getTag();
}
holder.versenumber.setText(versenumber.get(position));
holder.verselist.setText(verselist.get(position));
//verselist highlight
//share verse
holder.share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toasty.info(activity, "Sharing a verse.", Toast.LENGTH_SHORT, true).show();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, refernce.get(position) + ":" + versenumber.get(position) + '\n' + verselist.get(position));
sendIntent.setType("text/plain");
activity.startActivity(sendIntent);
}
});
//add in favourite
holder.addfavoruite.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
mDBHelper = new DatabaseHelper(activity);
mDb = mDBHelper.getWritableDatabase();
ContentValues contentValues=new ContentValues();
contentValues.put("id",verseid.get(position));
contentValues.put("bookname",refernce.get(position));
contentValues.put("versenumber",versenumber.get(position));
contentValues.put("verse",verselist.get(position));
long check=mDb.insert("favourite",null,contentValues);
Log.d("MY_TAG","DB IS NOW "+check);
Toasty.success(activity, "Added in favouite", Toast.LENGTH_SHORT, true).show();
}else {
mDBHelper = new DatabaseHelper(activity);
mDb = mDBHelper.getWritableDatabase();
long delete= mDb.delete("favourite","id=?",new String[]{verseid.get(position)});
Toasty.error(activity, "Remove in favouite", Toast.LENGTH_SHORT, true).show();
}
}
});
textToSpeech = new TextToSpeech(activity, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
result = textToSpeech.setLanguage(Locale.ENGLISH);
} else {
Toast.makeText(activity, "YOUR DEVICE NOT SUPPORTED", Toast.LENGTH_SHORT).show();
}
}
});
//My toggle button
holder.speakverse.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(activity, "I AM CLICKED", Toast.LENGTH_SHORT).show();
if (result == TextToSpeech.LANG_NOT_SUPPORTED || result == TextToSpeech.LANG_MISSING_DATA) {
Toast.makeText(activity, "Language not supported or Missing", Toast.LENGTH_SHORT).show();
} else {
textToSpeech.speak(verselist.get(position), TextToSpeech.QUEUE_FLUSH, null);
}
}
});
return convertView;
}
static class ViewHolder {
private TextView versenumber;
private TextView verselist;
private ImageView share;
private ToggleButton addfavoruite;
private ImageView speakverse;
public ViewHolder(View v) {
versenumber = (TextView) v.findViewById(R.id.versenumber);
verselist = (TextView) v.findViewById(R.id.verse);
share = (ImageView) v.findViewById(R.id.share);
speakverse = (ImageView) v.findViewById(R.id.speakverse);
addfavoruite=(ToggleButton)v.findViewById(R.id.adbookmark);
}
}
public boolean CheckIsDataAlreadyInDBorNot(String TableName, String dbfield, String fieldValue) {
mDBHelper = new DatabaseHelper(activity);
mDb = mDBHelper.getReadableDatabase();
String Query = "Select * from " + TableName + " where " + dbfield + " = " + fieldValue;
Cursor cursor = mDb.rawQuery(Query, null);
if(cursor.getCount() <= 0){
cursor.close();
Toast.makeText(activity, "false", Toast.LENGTH_SHORT).show();
return false;
}else {
Toast.makeText(activity, "TRUE", Toast.LENGTH_SHORT).show();
}
cursor.close();
return true;
}
public void opecolorpicker(){
ColorPicker colorPicker = new ColorPicker(activity);
ArrayList<String>colors=new ArrayList<>();
colors.add("#FF0000");
colors.add("#FFEC33");
colors.add("#3C33FF");
colors.add("#DA33FF");
colors.add("#33FF99");
colors.add("#90FF33");
colors.add("#DD33FF");
colors.add("#F0B27A");
colors.add("#DAF7A6");
colors.add("#34495E");
colorPicker.setColors(colors).setTitle("HIGHLIGHT VERSE").setRoundColorButton(true).setOnChooseColorListener(new ColorPicker.OnChooseColorListener() {
#Override
public void onChooseColor(int position, int color) {
Toast.makeText(activity, ""+color, Toast.LENGTH_SHORT).show();
}
#Override
public void onCancel() {
}
}).show();
}
}
Use this:
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
Toast.makeText(ALLVERSE.this, "LIFE RUNS ON CODE", Toast.LENGTH_SHORT).show();
}
});
Instead of:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(ALLVERSE.this, "LIFE RUNS ON CODE", Toast.LENGTH_SHORT).show();
}
});

Intro slide helper by viewPager

i wanted to use intro slider to my App
i learned it by this video https://www.youtube.com/watch?v=byLKoPgB7yA&t=22s
I do like video tutorial but I have a problem with dots
when I slide to any page the dots(. ) will be copy and increase
where is my problem and what should I do ?
package time.one.just.show.introslyder;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private ViewPager mSlideViewPager;
private LinearLayout mDotsLayout;
private SlyderAdapter slyderAdapter;
//dots of any Slide pages
private TextView[] mDots;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSlideViewPager = findViewById(R.id.viewPager);
mDotsLayout = findViewById(R.id.dots);
slyderAdapter = new SlyderAdapter(this);
mSlideViewPager.setAdapter(slyderAdapter);
addDotsIndiccator(0);
mSlideViewPager.addOnPageChangeListener(viewListener);
}
private void addDotsIndiccator(int position) {
mDots = new TextView[3];
for (int i = 0; i < mDots.length; i++) {
mDots[i] = new TextView(this);
mDots[i].setText(Html.fromHtml("&#8226"));
mDots[i].setTextSize(35);
mDots[i].setTextColor(getResources().getColor(R.color.colorWhiteNearToGray));
mDotsLayout.addView(mDots[i]);
}
if (mDots.length > 0) {
mDots[position].setTextColor(getResources().getColor(R.color.colorWite));
}
}
ViewPager.OnPageChangeListener viewListener = new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int i, float v, int i1) {
}
#Override
public void onPageSelected(int i) {
addDotsIndiccator(i);
}
#Override
public void onPageScrollStateChanged(int i) {
}
};}
And this is my SideAdapter class
package time.one.just.show.introslyder;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class SlyderAdapter extends PagerAdapter {
Context context;
LayoutInflater layoutInflater;
public SlyderAdapter(Context context) {
this.context = context;
}
public int[] slide_imagesArray = {
R.drawable.eat,
R.drawable.men,
R.drawable.sleep};
public String[] slide_headerArray = {
"EAT", "men", "code"};
public String[] slide_descriptionArray = {
"this is 1st", "this is 2nd", "this is 3rd"
};
#Override
public int getCount() {
return slide_headerArray.length;
}
#Override
public boolean isViewFromObject(#NonNull View view, #NonNull Object o) {
return view == o;
}
#NonNull
#Override
public Object instantiateItem(#NonNull ViewGroup container, int position) {
layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.slide_layoout, container, false);
ImageView slideImageView = (ImageView) view.findViewById(R.id.slideImage);
TextView slideheader = (TextView) view.findViewById(R.id.slideheader);
TextView slidedescription = (TextView) view.findViewById(R.id.slideDescription);
slideImageView.setImageResource(slide_imagesArray[position]);
slideheader.setText(slide_headerArray[position]);
slidedescription.setText(slide_descriptionArray[position]);
container.addView(view);
return view;
}
#Override
public void destroyItem(#NonNull ViewGroup container, int position, #NonNull Object object) {
container.removeView((RelativeLayout) object);
}
}
and this is my SliderLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:id="#+id/slideImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="89dp"
app:srcCompat="#drawable/eat" />
<TextView
android:id="#+id/slideheader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="122dp"
android:layout_marginBottom="287dp"
android:text="بدون نیاز به اینترنت"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/slideDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginBottom="171dp"
android:text="آرشیو کامل این خواننده محبوب همیشه در جیب شم ، ، هر کدام ز آهنگ ها را خواستید می توانید دانلود کنید و هر زمان دلتون خوست به آن ها گوش بدهید حتی بدون نیز به اینترنت" />
</RelativeLayout>
and activtymain xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/main_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
<LinearLayout
android:id="#+id/dots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal"></LinearLayout>
</RelativeLayout>
I found a solution
just by add this inside my App
mDotsLayout.removeAllViews();
thank you all

Refresh/update listview current tab

I have three tabs with an unique fragment. How by images:
3 tab and a fragment
First problem is that when I click on "I watch it" on a movie and swipe on Watched's tab, this tab isn't updated.
https://i.imgur.com/AnnN3Zq.png?1
https://i.imgur.com/DsLGn3r.png
After if I swipe/tap on Notify's tab and comeback on Watched's tab, the tab has been updated. Why? Where am I wrong?
CoreActivity.java
package com.example.msnma.movienotifier;
import android.annotation.TargetApi;
import android.app.FragmentTransaction;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.example.msnma.movienotifier.MoviesFragment;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.Toast;
import com.example.msnma.movienotifier.adapter.MoviesAdapter;
import com.example.msnma.movienotifier.notify.NotificationReceiver;
import com.example.msnma.movienotifier.event.TwoPaneEvent;
import org.greenrobot.eventbus.EventBus;
import butterknife.BindView;
import static android.support.v4.view.PagerAdapter.POSITION_NONE;
import static com.google.common.reflect.Reflection.initialize;
import static java.security.AccessController.getContext;
public class CoreActivity extends AppCompatActivity implements TabLayout.OnTabSelectedListener {
SectionsPageAdapter mSectionsPageAdapter;
#BindView(R.id.movies)
ViewPager mViewPager;
#BindView(R.id.tabs)
TabLayout tabLayout;
boolean twoPane;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_core);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(toolbar);
if (findViewById(R.id.movie_detail) != null) {
twoPane = true;
}
mSectionsPageAdapter = new SectionsPageAdapter(getSupportFragmentManager(), twoPane);
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setOffscreenPageLimit(1);
mViewPager.setAdapter(mSectionsPageAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
tabLayout.addOnTabSelectedListener(
new TabLayout.ViewPagerOnTabSelectedListener(mViewPager) {
#Override
public void onTabSelected(TabLayout.Tab tab) {
super.onTabSelected(tab);
final int numTab = tab.getPosition();
//Toast.makeText(getApplicationContext(),tab.getText(), Toast.LENGTH_LONG).show();
switch (tab.getPosition()) {
case 0: {
MoviesAdapter.setTipo(String.valueOf(MoviesFragment.Type.NOTIFY));
break;
}
case 1: {
MoviesAdapter.setTipo(String.valueOf(MoviesFragment.Type.SUGGESTED));
break;
}
case 2: {
MoviesAdapter.setTipo(String.valueOf(MoviesFragment.Type.WATCHED));
break;
}
}
}
});
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
//mViewPager.setCurrentItem(position);
// ci sono vicinissimo alla soluzione.
if(position == 0 || position == 2) {
Fragment getFragment = getSupportFragmentManager().getFragments().get(position);
if (getFragment instanceof MoviesFragment) {
MoviesFragment thisFragment = (MoviesFragment) getFragment;
thisFragment.onRefresh();
Log.i("REFRESH","Dovrebbe essere refreshato");
}
Log.i("PAGINASELEZIONATA", "Esegue onResume " + position);
}
//Toast.makeText(CoreActivity.this,"Tab "+position,Toast.LENGTH_LONG).show();
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
EventBus.getDefault().postSticky(new TwoPaneEvent(twoPane));
}
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_second, menu);
//MenuItem item = menu.findItem(R.id.search);
//searchView.setMenuItem(item);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
public void pressAccountButton(MenuItem item)
{
Intent intent = new Intent(this, AccountActivity.class);
startActivity(intent);
}
//nuovo codice
#Override
protected void onResume()
{
super.onResume();
if (!(mSectionsPageAdapter == null)) {
mSectionsPageAdapter.notifyDataSetChanged();
Log.i("INFOonResume", "Metodo onResume eseguito");
}
}
#Override
public void onTabSelected(TabLayout.Tab tab) {
//Log.i("INFOTAB", "La tabella selezionata è "+tab.getTag());
onResume();
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
}
Tap Notify's tap (believe also could tap on Suggested) and tap again Watched's tap
Second problem
In Watched's tab the textView are cut, why? How can I solve this?
MoviesAdapter.java
package com.example.msnma.movienotifier.adapter;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.example.msnma.movienotifier.MainActivity;
import com.example.msnma.movienotifier.MoviesFragment;
import com.example.msnma.movienotifier.R;
import com.example.msnma.movienotifier.database.MovieDatabase;
import com.example.msnma.movienotifier.databaseModel.MovieDBModel;
import com.example.msnma.movienotifier.model.Movie;
import java.util.Calendar;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Optional;
import static android.app.PendingIntent.getActivity;
import static com.example.msnma.movienotifier.MoviesFragment.*;
public class MoviesAdapter extends RecyclerView.Adapter<MoviesAdapter.ViewHolder>{
private Context context;
private List<Movie> movies;
private View itemView;
private RecyclerView rv;
//per la data
private EditText fromDateEtxt;
private boolean active = false;
//private Context context;
private static String tipo = "NOTIFY";
public MoviesAdapter(Context context, List<Movie> movies) {
this.context = context;
this.movies = movies;
}
#Override
public MoviesAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View itemView;
/*if(getTipo().equals("Suggested"))
{
itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_movie, parent, false);
return new ViewHolder(itemView);
}
else if(getTipo().equals("Watched"))
{
itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_movie_watched, parent, false);
return new ViewHolder(itemView);
}
else if(getTipo().equals("Notify"))
{*/
itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_movie, parent, false);
return new ViewHolder(itemView);
//}
//return null;
}
#Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
Movie movie = movies.get(position);
Glide.with(context)
.load(movie.getPosterUrl())
.placeholder(R.drawable.poster_placeholder)
.into(holder.posterView);
holder.title_movie.setText(movie.getTitle());
// prende solo la data + anno
String yourString = String.valueOf(movie.getReleaseDate());
String date = yourString.substring(0, 10);
String year = yourString.substring(yourString.length()-5,yourString.length());
holder.release_date.setText(date+year);
if(getTipo().equals("NOTIFY"))
{
Toast.makeText(context,"Notify", Toast.LENGTH_LONG).show();
holder.notifyButton.setVisibility(View.GONE);
holder.watchedButton.setVisibility(View.GONE);
holder.removeButton.setVisibility(View.VISIBLE);
}
//solo se è di tipo suggested
if(getTipo().equals("SUGGESTED"))
{
//disabilitare bottone remove
holder.removeButton.setVisibility(View.GONE);
holder.notifyButton.setVisibility(View.VISIBLE);
holder.watchedButton.setVisibility(View.VISIBLE);
Toast.makeText(context,"Suggested", Toast.LENGTH_LONG).show();
holder.notifyButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
/*String testo = movies.get(position).getTitle().toString();
Toast tostato = Toast.makeText(context,testo,Toast.LENGTH_SHORT);
tostato.show();*/
alertFormElements(position);
}
});
holder.watchedButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
/*String testo = movies.get(position).getTitle()+ "\n" + "I WATCH IT";
Toast tostato = Toast.makeText(context,testo,Toast.LENGTH_SHORT);
tostato.show();*/
// public MovieDBModel(int id, String title, String overview, String posterUrl, String backdropUrl, String trailerUrl,
// Date releaseDate, float rating, boolean adult){
MovieDBModel mdm = new MovieDBModel(movies.get(position).getId(), movies.get(position).getTitle(), movies.get(position).getOverview(),
movies.get(position).getPosterUrl(), movies.get(position).getBackdropUrl(), movies.get(position).getTrailerUrl(),
movies.get(position).getReleaseDate(), movies.get(position).getRating(), movies.get(position).isAdult());
MovieDatabase.insertMovie(mdm, 2, MainActivity.getMovieDatabase());
String testo = "Added " + movies.get(position).getTitle() + "\n" + "in tab watched";
Toast tostato = Toast.makeText(context, testo, Toast.LENGTH_SHORT);
tostato.show();
}
});
}
if (getTipo().equals("WATCHED"))
{
holder.notifyButton.setVisibility(View.GONE);
holder.watchedButton.setVisibility(View.GONE);
holder.removeButton.setVisibility(View.VISIBLE);
holder.removeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view)
{
//da implementare
}
});
Toast.makeText(context,"WATCHED", Toast.LENGTH_LONG).show();
}
}
//nuovo codice riguardo l'alerDialog
public final void alertFormElements(final int position)
{
/*
* Inflate the XML view. activity_main is in
* res/layout/form_elements.xml
*/
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View formElementsView = inflater.inflate(R.layout.form_elements,
null, false);
// You have to list down your form elements
/*final CheckBox myCheckBox = (CheckBox) formElementsView
.findViewById(R.id.myCheckBox);*/
final RadioGroup genderRadioGroup = (RadioGroup) formElementsView
.findViewById(R.id.NotifyAlertRadioGroup);
//nuovo codice
genderRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
#Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
switch (checkedId)
{
case R.id.OneDayRadioButton:
actv(false);
break;
case R.id.ReleaseDayRadioButton:
actv(false);
break;
case R.id.OnRadioButton:
actv(true);
break;
}
}
});
//questo sarà sostituito con un calendario.
/*final EditText nameEditText = (EditText) formElementsView
.findViewById(R.id.nameEditText);*/
//parte data
fromDateEtxt = (EditText) formElementsView.findViewById(R.id.nameEditText);
fromDateEtxt.setEnabled(active);
fromDateEtxt.setClickable(active);
fromDateEtxt.setInputType(InputType.TYPE_NULL);
fromDateEtxt.requestFocus();
//metodo data
//setDateTimeField();
//fromDatePickerDialog.show();
fromDateEtxt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
DatePickerDialog dpd = new DatePickerDialog( context ,
new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
fromDateEtxt.setText(dayOfMonth + "-"
+ (monthOfYear + 1) + "-" + year);
}
},
c.get(Calendar.YEAR),
c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH));
dpd.show();
}
});
// the alert dialog
new AlertDialog.Builder(context).setView(formElementsView)
.setTitle(movies.get(position).getTitle()+" Notify")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#TargetApi(11)
public void onClick(DialogInterface dialog, int id) {
//fromDateEtxt.setText(dateFormatter.format(newDate.getTime()));
String toastString = "";
String titleMovie = movies.get(position).getTitle();
String releaseDate = String.valueOf(movies.get(position).getReleaseDate());
String date = releaseDate.substring(0, 10);
String year = releaseDate.substring(releaseDate.length()-5,releaseDate.length());
releaseDate = date+year;
toastString = toastString + titleMovie + "\n" + releaseDate +"\n";
/*
* Detecting whether the checkbox is checked or not.
*/
/*if (myCheckBox.isChecked()) {
toastString += "Happy is checked!\n";
} else {
toastString += "Happy IS NOT checked.\n";
}*/
/*
* Getting the value of selected RadioButton.
*/
// get selected radio button from radioGroup
int selectedId = genderRadioGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
RadioButton selectedRadioButton = (RadioButton) formElementsView
.findViewById(selectedId);
if(selectedRadioButton.getId() == R.id.OnRadioButton)
{
toastString += "Selected radio button is: " + fromDateEtxt.getText();
}
else {
toastString += "Selected radio button is: "
+ selectedRadioButton.getText() + "!\n";
}
/*
* Getting the value of an EditText.
*/
/*toastString += "Name is: " + nameEditText.getText()
+ "!\n";*/
Toast toast = Toast.makeText(context, toastString, Toast.LENGTH_LONG);
toast.show();
dialog.cancel();
}
}).show();
}
//nuovo codice
/*#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item_movie, null);
holder = new ViewHolder();
holder.title_movie = (TextView) convertView.findViewById(R.id.movie_title);
holder.release_date = (TextView) convertView
.findViewById(R.id.movie_release_date);
Movie row_pos = movies.get(position);
//holder.profile_pic.setImageResource(row_pos.getProfile_pic_id());
holder.title_movie.setText(row_pos.getTitle());
holder.release_date.setText((CharSequence) row_pos.getReleaseDate());
//holder.contactType.setText(row_pos.getContactType());
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}*/
#Override
public void onViewRecycled(ViewHolder holder) {
super.onViewRecycled(holder);
Glide.clear(holder.posterView);
}
#Override
public int getItemCount() {
return movies.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
#BindView(R.id.poster)
public ImageView posterView;
#BindView(R.id.movie_title)
public TextView title_movie;
#BindView(R.id.movie_release_date)
public TextView release_date;
#BindView(R.id.editNotify)
public Button notifyButton;
#BindView(R.id.iWatchItMovie)
public Button watchedButton;
#BindView(R.id.remove)
public Button removeButton;
public ViewHolder(View v) {
super(v);
ButterKnife.bind(this, v);
}
}
//parte per attivare/disattivare l'editText
private void actv(final boolean active)
{
fromDateEtxt.setEnabled(active);
if (active)
{
fromDateEtxt.requestFocus();
}
}
public static void setTipo(String tipo) {
MoviesAdapter.tipo = tipo;
}
public static String getTipo() {
return tipo;
}
}
For first, you can try adding similar logic to onPageScrolled
Fragment getFragment = getSupportFragmentManager().getFragments().get(position);
if (getFragment instanceof MoviesFragment) {
MoviesFragment thisFragment = (MoviesFragment) getFragment;
if ((position == 0 || position == 2) && positionOffset == 0.0 && positionOffsetPixels == 0)
thisFragment.onRefresh();
}
OK, #user47845 for (This is my list_item_movie.xml) you can try changed to this and tell us how are you doing.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="350px">
<android.support.constraint.ConstraintLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/card_background">
<ImageView
android:id="#+id/poster"
android:layout_width="120dp"
android:layout_height="139dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="10dp"
android:layout_marginStart="2dp"
android:contentDescription="TODO"
android:scaleType="centerCrop"
android:src="#drawable/poster_placeholder"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/movie_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textSize="20dip"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/poster"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/movie_release_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="20dip"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/poster"
app:layout_constraintTop_toBottomOf="#+id/movie_title" />
<Button
android:id="#+id/editNotify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:onClick="pressEditNotifyButton"
android:text="Notify"
android:textColor="#android:color/holo_blue_dark"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#+id/poster" />
<Button
android:id="#+id/iWatchItMovie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:text="I watch it"
android:textColor="#android:color/holo_blue_dark"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="#+id/remove"
app:layout_constraintStart_toEndOf="#+id/movie_title"
app:layout_constraintBottom_toBottomOf="parent" />
<Button
android:id="#+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="21dp"
android:layout_marginRight="21dp"
android:background="#android:color/transparent"
android:text="Remove"
android:textColor="#android:color/holo_blue_dark"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/iWatchItMovie" />
</android.support.constraint.ConstraintLayout>
</FrameLayout>
This is my list_item_movie.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="350px">
<!--android:layout_height="?android:attr/listPreferredItemHeight">-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="#drawable/card_background">
<ImageView
android:id="#+id/poster"
android:layout_width="185px"
android:layout_height="277px"
android:src="#drawable/poster_placeholder"
android:scaleType="centerCrop"
android:contentDescription="TODO" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
android:id="#+id/movie_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textStyle="bold"
android:layout_gravity="left|center_vertical"
android:textSize="20dip"
android:layout_marginLeft="10dip"
/>
<TextView
android:id="#+id/movie_release_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="left|center_vertical"
android:textSize="20dip"
android:layout_marginLeft="10dip"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="horizontal">
<Button
android:id="#+id/editNotify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:onClick="pressEditNotifyButton"
android:text="Notify"
android:textColor="#android:color/holo_blue_dark"
android:textStyle="bold" />
<Button
android:id="#+id/iWatchItMovie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:text="I watch it"
android:textColor="#android:color/holo_blue_dark"
android:textStyle="bold" />
<Button
android:id="#+id/remove"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:text="Remove"
android:textColor="#android:color/holo_blue_dark"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
EDIT:
I have solved so:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="350px">
<!--android:layout_height="?android:attr/listPreferredItemHeight">-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginTop="4dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="4dp"
android:orientation="horizontal"
android:background="#drawable/card_background">
<ImageView
android:id="#+id/poster"
android:layout_width="185px"
android:layout_height="277px"
android:contentDescription="TODO"
android:scaleType="centerCrop"
android:src="#drawable/poster_placeholder" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/movie_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:textSize="20dip"
android:textStyle="bold" />
<TextView
android:id="#+id/movie_release_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:textSize="20dip" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="horizontal">
<Button
android:id="#+id/editNotify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:onClick="pressEditNotifyButton"
android:text="Notify"
android:textColor="#android:color/holo_blue_dark"
android:textStyle="bold" />
<Button
android:id="#+id/iWatchItMovie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:text="I watch it"
android:textColor="#android:color/holo_blue_dark"
android:textStyle="bold" />
<Button
android:id="#+id/remove"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:text="Remove"
android:textColor="#android:color/holo_blue_dark"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>

How do I retrieve the ID number of this text view

How do I retrieve the text of a specific textView? BEcause when I click an ID number it displays '1' in the textview of the next class in every text view I click. I used JSON array so it's kind of tricky for me. And yes I'm completely a beginner.
DisplayListView
package rjj.tutorial_jsonandlistview;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class DisplayListView extends AppCompatActivity {
String json_string;
JSONObject jsonObject;
JSONArray jsonArray;
ContactAdapter contactAdapter;
ListView listView;
SearchView sv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display_listview_layout);
listView = (ListView)findViewById(R.id.listview);
contactAdapter = new ContactAdapter(this,R.layout.row_layout);
listView.setAdapter(contactAdapter);
json_string = getIntent().getExtras().getString("json_data");
//Searchview
sv = (SearchView)findViewById(R.id.search);
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
contactAdapter.getFilter().filter(newText);
return true;
}
});
//End of Searchview
try {
jsonObject = new JSONObject(json_string);
jsonArray = jsonObject.getJSONArray("server_response");
int count = 0;
String id ,firstname , surname, age , username, password;
while(count<jsonArray.length()){
JSONObject JO = jsonArray.getJSONObject(count);
id = JO.getString("id");
firstname = JO.getString("firstname");
surname = JO.getString("surname");
age = JO.getString("age");
username = JO.getString("username");
password = JO.getString("password");
Contacts contact = new Contacts(id, firstname, surname, age,username,password);
contactAdapter.add(contact);
count++;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public void hello(View view) {
Intent intent = new Intent(this, Update.class);
TextView textView = (TextView)findViewById(R.id.tx_id);
String id = textView.getText().toString();
intent.putExtra("id", id);
startActivity(intent);
}
}
My ContactAdapter Class:
package rjj.tutorial_jsonandlistview;
import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Julian on 7/20/2017.
*/
public class ContactAdapter extends ArrayAdapter {
List list = new ArrayList();
public ContactAdapter(#NonNull Context context, #LayoutRes int resource) {
super(context, resource);
}
public void add(Contacts object) {
super.add(object);
list.add(object);
}
#Override
public int getCount() {
return list.size();
}
#Nullable
#Override
public Object getItem(int position) {
return list.get(position);
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
View row;
row = convertView;
ContactHolder contactHolder;
if(row == null){
LayoutInflater layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(R.layout.row_layout,parent,false);
contactHolder = new ContactHolder();
contactHolder.tx_id = (TextView)row.findViewById(R.id.tx_id);
contactHolder.tx_firstname = (TextView)row.findViewById(R.id.tx_firstname);
contactHolder.tx_surname = (TextView)row.findViewById(R.id.tx_surname);
contactHolder.tx_age = (TextView)row.findViewById(R.id.tx_age);
contactHolder.tx_username = (TextView)row.findViewById(R.id.tx_username);
contactHolder.tx_password = (TextView)row.findViewById(R.id.tx_password);
row.setTag(contactHolder);
} else{
contactHolder = (ContactHolder)row.getTag();
}
Contacts contacts = (Contacts)this.getItem(position);
contactHolder.tx_id.setText(contacts.getId());
contactHolder.tx_firstname.setText(contacts.getFirstname());
contactHolder.tx_surname.setText(contacts.getSurname());
contactHolder.tx_age.setText(contacts.getAge());
contactHolder.tx_username.setText(contacts.getUsername());
contactHolder.tx_password.setText(contacts.getPassword());
return row;
}
static class ContactHolder{
TextView tx_id, tx_firstname, tx_surname, tx_age, tx_username, tx_password;
}
}
My Update Class:
package rjj.tutorial_jsonandlistview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class Update extends AppCompatActivity {
String id;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update);
id = getIntent().getExtras().getString("id");
TextView textView = (TextView)findViewById(R.id.textView);
textView.setText(id);
}
}
My display_listview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="rjj.tutorial_jsonandlistview.DisplayListView">
<SearchView
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/search"
android:queryHint="Search..."/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/search"
android:id="#+id/listview">
</ListView>
</android.widget.RelativeLayout>
The row_layout.xml (which I use to display the JSON array)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="75dp">
<TextView
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="#+id/tx_id"
android:layout_alignParentLeft="true"
android:text="ID"
android:gravity="center"
android:textAppearance="?android:textAppearanceLarge"
android:onClick="hello"
/>
<TextView
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="#+id/tx_firstname"
android:layout_toRightOf="#+id/tx_id"
android:text="Firstname"
android:gravity="center"
android:textAppearance="?android:textAppearanceLarge"
/>
<TextView
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="#+id/tx_surname"
android:layout_toRightOf="#+id/tx_firstname"
android:text="Lastname"
android:gravity="center"
android:textAppearance="?android:textAppearanceLarge"
/>
<TextView
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="#+id/tx_age"
android:layout_toRightOf="#+id/tx_surname"
android:text="Age"
android:gravity="center"
android:textAppearance="?android:textAppearanceLarge"
/>
<TextView
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="#+id/tx_username"
android:layout_toRightOf="#+id/tx_age"
android:text="Username"
android:gravity="center"
android:textAppearance="?android:textAppearanceLarge"
/>
<TextView
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="#+id/tx_password"
android:layout_toRightOf="#+id/tx_username"
android:text="Password"
android:gravity="center"
android:textAppearance="?android:textAppearanceLarge"
/>
</RelativeLayout>
In method hello(View view) you don't need this string:
TextView textView = (TextView)findViewById(R.id.tx_id);
becouse the view in hello(View view) this is our TextView. Just cast it to TextView and get text from it:
String id = ((TextView)view).getText().toString();
Another and most universal approach: to change
TextView textView = (TextView)findViewById(R.id.tx_id);
to
TextView textView = (TextView)((ViewGroup)(view.getParent())).findViewById(R.id.tx_id);
In this way you can use any R.id for current list item.

Categories

Resources