• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Redirection Problem

Osman Nour

Lurker
Aug 27, 2020
1
0
Hello,
I program an android application which consists of customer management. When I click on search, the app gives me a list with half of my data. So wen i click on the list, I want the app redirects me to a new activity with all of my data. someone can help me. here is the interface code and the overview.

Java:
package com.example.arulos;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.Cursor;
import android.icu.text.Transliterator;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class Rechcerche extends AppCompatActivity {

    EditText editText_propriétaire;
    EditText editText_cni;
    DatabaseHelper mydb;
    Button button_rechercher;
    Button button_annuler;
    ListView listView;


    ArrayList<String> nom_client = new ArrayList<>();
     //String[] nom_client;

    ArrayList<String> num_cni = new ArrayList<>();
   // String[] num_cni;

    ArrayList<String> tel = new ArrayList<>();
   // String[] tel;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rechcerche);

        editText_propriétaire = (EditText) findViewById(R.id.edt_propriétaire);
        editText_cni = (EditText) findViewById(R.id.edt_cni);
        button_rechercher = (Button) findViewById(R.id.btn_recherche);
        button_annuler = (Button) findViewById(R.id.btn_annuler);


        listView = (ListView) findViewById(R.id.list_view);
       // final   MyListAdapter adapter=new MyListAdapter();
        listView.setAdapter(null);

        listView.setClickable(true);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //  Toast.makeText(getApplicationContext(), ""+position, Toast.LENGTH_LONG).show();
                Log.d("position",position+"");
            }
        });


        mydb = new DatabaseHelper(this);

        button_rechercher.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {

                afficher();
            }
        });

        button_annuler.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                editText_propriétaire.getText().clear();
                editText_cni.getText().clear();
                nom_client.clear();
                num_cni.clear();
                tel.clear();
            }
        });


    //listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
      //      @Override
        //    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

          //    Intent intent = new Intent(Rechcerche.this, Detail_client.class);
            //         Bundle bundle = new Bundle();
              // bundle.putParcelableArrayList("mylist", nom_client);
                // intent.putExtras(bundle);
              // startActivity(intent);
                /*String Templistview = nom_client[Position].toString
                    Intent intent = new Intent(view.getContext(),Detail_client.class);
                    startActivity(intent);*/

           //}
        //}

    }
    protected void afficher(){
    //   ArrayList<String> theList = new ArrayList<>();
      // ArrayList<String> theList1 = new ArrayList<>();
        //ArrayList<String> theList2 = new ArrayList<>();
        String nom = editText_propriétaire.getText().toString().trim();
        String cni = editText_cni.getText().toString().trim();

        Cursor data = mydb.chercher(nom,cni);
        if (data.getCount() == 0) {
            Toast.makeText(this, "There are no contents in this list!", Toast.LENGTH_LONG).show();
        } else if ((data!=null && data.getCount() > 0)) {

            Toast.makeText(this, "There are contents in this list!", Toast.LENGTH_LONG).show();

          if (data.moveToFirst()) {
              do{
                  nom_client.add( data.getString(data.getColumnIndex("nom_client")));
                  num_cni.add(data.getString(data.getColumnIndex("numero_cni")));
                  tel.add(data.getString(data.getColumnIndex("telephone")));
                  //theList.add("Numero cni :" + data.getString(2));

              }while(data.moveToNext());
             // ListAdapter listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, theList);
              //listView.setAdapter(listAdapter);
              final   MyListAdapter adapter=new MyListAdapter(this, nom_client,num_cni,tel);
              listView.setAdapter(adapter);

             data.close();
            }

           /* for(int i=0 ; i<theList.size();i++){
                theList.add("Nom :" + data.getString(1) +"\t" + "Numero cni :" + data.getString(2));
                //theList.add("Numero cni :" + data.getString(2));
                ListAdapter listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, theList);
                listView.setAdapter(listAdapter);
            }*/
        }
    }
}

Code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
    android:orientation="vertical"
    android:background="@drawable/back_recherhche"
    android:gravity="center_horizontal"
    tools:context=".Rechcerche">

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical"
         android:gravity="center_horizontal">



    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/logo1"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="Remplir les deux champs pour faire votre recherche"
        android:textStyle="italic"
        android:textColor="@android:color/black"
        />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="160dp"
            android:layout_height="50dp"
            android:text="Propriétaire:"
            android:textStyle="bold"
            android:textSize="20dp"
            android:textColor="@android:color/black"
            android:layout_marginRight="230dp"/>

        <EditText
            android:id="@+id/edt_propriétaire"
            android:layout_width="260dp"
            android:layout_height="50dp"
            android:layout_marginLeft="-250dp"
            android:background="@android:color/white"
            />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="160dp"
            android:layout_height="50dp"
            android:text="Numero CNI:"
            android:textStyle="bold"
            android:textSize="20dp"
            android:textColor="@android:color/black"
            android:layout_marginRight="230dp"/>

        <EditText
            android:id="@+id/edt_cni"
            android:layout_width="260dp"
            android:layout_height="50dp"
            android:layout_marginLeft="-250dp"
            android:background="@android:color/white"
            />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:orientation="horizontal">
    <Button
        android:id="@+id/btn_recherche"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:text="Rechercher"
        android:textStyle="bold"
        android:background="#21f505"/>
    <Button
        android:id="@+id/btn_annuler"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:text="Annuler"
        android:textStyle="bold"
        android:layout_marginLeft="50dp"
        android:background="#e31005" />

    </LinearLayout>




    <ListView
        android:id="@+id/list_view"
        android:layout_width="wrap_content"
        android:layout_height="328dp"
        android:layout_marginTop="20dp"
        android:textColor="@color/colorPrimary"
        android:textSize="20dp"
        android:textStyle="bold" />

     </LinearLayout>

</ScrollView>
package com.example.arulos;
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones