Click here to Skip to main content
15,919,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to make an android listview when the list item is clicked shows a textview of paragraph of words with zoom controls.thank you.
Posted

Create the listview in one activity then on item click open another activity and pass the string to the new activity then in the new activity set the passed string as the text in the text view as for the zoom controls I recommend just increasing And decreasing the font if it is just The text you are zooming in and out on. If you need help with the code just ask and I'll do my best to steer you in the the direction.

Alright here you go not sure if this is exactly what your looking for but at least its a start:

activity_main.xml
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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.karthikvambakad.myapplication.MainActivity"
    tools:showIn="@layout/activity_main">

   <ListView
       android:id="@+id/mainListView"
       android:layout_width="match_parent"
       android:layout_height="match_parent"></ListView>
</RelativeLayout>


MainActivity.class
Java
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    ListView myListView;
    List<String> your_array_list = new ArrayList<String>();

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

        myListView = (ListView)findViewById(R.id.mainListView);
        //Populate the array
        your_array_list.add("test1");
        your_array_list.add("test2");
        your_array_list.add("test3");
        your_array_list.add("test4");
        your_array_list.add("test5");
        your_array_list.add("test6");
        your_array_list.add("test7");
        your_array_list.add("test8");
        your_array_list.add("test9");
        your_array_list.add("test10");
        //set array to adapter
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                MainActivity.this,
                android.R.layout.simple_list_item_1,
                your_array_list );
        //set listview adapter
        myListView.setAdapter(arrayAdapter);


        myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //making a paragraph string to store the paragraph text
                String paragraph = "";
                //ifstatement to compare the values and set the paragraph based on the selected item
                if(myListView.getItemAtPosition(position).toString().trim().equals("test1")){
                    //setting value of the paragraph string
                    paragraph = "your paragraph for test1 goes here";
                }
                else if(myListView.getItemAtPosition(position).toString().trim().equals("test2")){
                    //setting value of the paragraph string
                    paragraph = "your paragraph for test2 goes here";
                }
                else if(myListView.getItemAtPosition(position).toString().trim().equals("test3")){
                    //setting value of the paragraph string
                    paragraph = "your paragraph for test3 goes here";
                }
                else if(myListView.getItemAtPosition(position).toString().trim().equals("test4")){
                    //setting value of the paragraph string
                    paragraph = "your paragraph for test4 goes here";
                }
                else if(myListView.getItemAtPosition(position).toString().trim().equals("test5")){
                    //setting value of the paragraph string
                    paragraph = "your paragraph for test5 goes here";
                }
                else if(myListView.getItemAtPosition(position).toString().trim().equals("test6")){
                    //setting value of the paragraph string
                    paragraph = "your paragraph for test6 goes here";
                }
                else if(myListView.getItemAtPosition(position).toString().trim().equals("test7")){
                    //setting value of the paragraph string
                    paragraph = "your paragraph for test7 goes here";
                }
                else if(myListView.getItemAtPosition(position).toString().trim().equals("test8")){
                    //setting value of the paragraph string
                    paragraph = "your paragraph for test8 goes here";
                }
                else if(myListView.getItemAtPosition(position).toString().trim().equals("test9")){
                    //setting value of the paragraph string
                    paragraph = "your paragraph for test9 goes here";
                }
                else if(myListView.getItemAtPosition(position).toString().trim().equals("test10")){
                    //setting value of the paragraph string
                    paragraph = "your paragraph for test10 goes here";
                }
                else {
                    //setting value of the paragraph string
                    paragraph = "no value set";
                }

                //starting the new activity and passing the paragraph to the activity using the intent
                Intent i = new Intent(MainActivity.this, DisplayActivity.class);
                i.putExtra("paragraph", paragraph);
                startActivity(i);

            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        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);
    }
}


activity_display.xml
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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.karthikvambakad.myapplication.DisplayActivity"
    tools:showIn="@layout/activity_display">

    <TextView
        android:id="@+id/displayTextView"
        android:layout_width="match_parent"
        android:layout_height="450dp" />
    <ZoomControls
        android:id="@+id/textZoomControl"
        android:layout_width="match_parent"
        android:gravity="center"
        android:layout_below="@+id/displayTextView"
        android:layout_height="wrap_content"></ZoomControls>
</RelativeLayout>


DisplayActivity.class
Java
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.ZoomControls;

public class DisplayActivity extends AppCompatActivity {

    String paragraphString = "";
    TextView displayTextView;
    ZoomControls textZoomControls;
    float textSize = 0;

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

        displayTextView = (TextView) findViewById(R.id.displayTextView);
        textZoomControls = (ZoomControls) findViewById(R.id.textZoomControl);

        //getting the value set from the other activity passed by the keyword paragraph
        Intent intent = getIntent();
        paragraphString = intent.getExtras().getString("paragraph");

        displayTextView.setText(paragraphString);
        
        //retrieving the size of the current textview size
        textSize = displayTextView.getTextSize();

        textZoomControls.setOnZoomInClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //incrementing size and setting textsize to the new value
                textSize++;

                displayTextView.setTextSize(textSize);
            }
        });

        textZoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //incrementing size and setting textsize to the new value
                textSize--;

                displayTextView.setTextSize(textSize);

            }
        });
    }

}


Hopefull that gets you started if you have any questions or ideas to better the code feel free to contact me and ill do my best to helpout.
 
Share this answer
 
v2
Comments
helloandroidjohn 31-Dec-15 11:21am    
hello karthik v ambakad can you please send me the code for the above listview =itemclick=pass string=textview with fonnt size .thanks for your kindness in replying.
Karthik V Ambakad 31-Dec-15 17:14pm    
Updated the post
hello karthik v ambakad can you please send me the code for the above listview =itemclick=pass string=textview with fonnt size .thanks for your kindness in replying.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900