listview的android示例clicked = textview带有段落和缩放控件源代码 [英] android example of listview clicked=textview with a paragraph and zoom controls source code

查看:70
本文介绍了listview的android示例clicked = textview带有段落和缩放控件源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击列表项时如何制作android列表视图显示带缩放控件的单词段的文本视图。谢谢。

how to make an android listview when the list item is clicked shows a textview of paragraph of words with zoom controls.thank you.

推荐答案

在一个活动中创建列表视图然后在项目上单击打开另一个活动并将该字符串传递给新活动然后在新活动中将传递的字符串设置为文本视图中的文本与缩放控件一样我建议只增加和减少字体如果它只是您放大和缩小的文本。如果您需要有关代码的帮助,请询问,我会尽力引导您朝着这个方向前进。



好​​了,你不确定这是不是确切你在寻找什么,但至少它是一个开始:



activity_main.xml

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 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



MainActivity.class

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



activity_display.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



DisplayActivity.class

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可以帮助您入门更好的代码随时联系我,并尽我所能帮忙。



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.


你好karthik v ambakad你可以给我发送上面listview = itemclick = pass string = textview的代码大小。感谢你的回复。
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.


这篇关于listview的android示例clicked = textview带有段落和缩放控件源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆