本文介绍了如何添加个人/相关名单按字母顺序排列的GridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我,如何列表项添加到网格view..for example..i有像A..Z字母网格视图。
.suppose如果我在字母A单击应该去另一个布局和展示陈列的含量[即一个相关列表],也
 如果我在应该显示在另一个B及其相关名单网格视图乙字母点击铺陈,很快点击按钮..
我希望你得到了我的requirement.can请你告诉我,我该怎么做..
希望你重播我。

can anyone tell me that how to add list items to grid view..for example..i have grid view like A..Z letters..suppose if i click on letter A that should go to another layout and show display A content[i.e a related list] and also if i click on B letter of grid view that should display b related list in another lay out and soon buttons click..i hope you got my requirement.can you please tell me how can i do that..hope you replay me.

例如::
我有这样一个列表视图网格
[A B C D
 E F G H
........
....... Z]
我需要的回答是:
如果我们点击字母A应该像这样显示
A [pressed],然后
阿沛
阿贾伊
阿伦
在B信$ P $然后pssed
B〔pressed]
Brahmaiah
bharth
bhargav。
像上面我想显示网格view.please帮助我在

for example::i have a list gird view like this[A B C D E F G H...............Z]my require answer is:if we click on letter A that should display like thisA[pressed]thenAbhayAjayArunif B letter pressed thenB[pressed]Brahmaiahbharthbhargav.like above i want to display grid view.please help me in that

GridViewActivity.java

GridView gridView;

static final String[] numbers = new String[]{
        "A", "B", "C", "D", "E",
        "F", "G", "H", "I", "J",
        "K", "L", "M", "N", "O",
        "P", "Q", "R", "S", "T",
        "U", "V", "W", "X", "Y", "Z"};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.content_main);

    gridView = (GridView) findViewById(R.id.gridView1);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, numbers);

    gridView.setAdapter(adapter);

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
                                int position, long id) {
            Toast.makeText(getApplicationContext(),
                    "" + position, Toast.LENGTH_SHORT).show();
            Intent intent = null;
            intent = new Intent(getApplicationContext(), ListActivity.class);

            startActivity(intent);
        }
    });

}

}
....
这是我的活动类..我想相关的内容添加到列表中的每一个字母present。
...

}....this is my activity class ..i want to add related content to every letter present in the list....

推荐答案

GridViewActivity.java

GridViewActivity.java

    public class GridViewActivity extends Activity {

        GridView gridView;

        static final String[] numbers = new String[] {
                "A", "B", "C", "D", "E",
                "F", "G", "H", "I", "J",
                "K", "L", "M", "N", "O",
                "P", "Q", "R", "S", "T",
                "U", "V", "W", "X", "Y", "Z"};

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            gridView = (GridView) findViewById(R.id.gridView1);

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, numbers);

            gridView.setAdapter(adapter);

            gridView.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                   Intent intent = null;
                   intent = new Intent(getApplicationContext(), ListActivity.class);
                   // Send the position to the next activity
                   // i.e. position 0 -> numbers[0] -> "A"
                   intent.putExtra("PositionToList", position);
                   startActivity(intent);
                }
            });

        }

    }

ListActivity.java

ListActivity.java

public class ListActivity extends Activity {

    // Dummy array, Only for example purposes!!!
    // In real life you will fetch data from somewhere else (i.e. DB, file, resources, network)
    static final String[][] list = new String[][] {
                {"Abhay", "Ajay", "Arun"},
                {"Brahmaiah", "bharth", "bhargav"},
                ....,
                ....,
                ....};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Get the position in order to know the data to be displayed
        Intent intent = getIntent();
        int position = intent.getIntExtra("PositionToList", 0); // here 0 is the default value

        // Set the content to display in your adapter
        ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list[position]);
        ListView myList = (ListView)findViewById(R.id.listView);
        myList.setAdapter(myAdapter);
    }
}

重要提示
真正的问题在这里展示的是不是code本身(我没有检查它是否编译顺便说一句),但如何与其他交流活动的想法。

ImportantThe real point to show here is not the code itself (I didn't check if it compiles btw) but the idea of how to communicate with other activities.


  1. 首先,你要选择你的GridActivity的东西,然后根据你想显示在你的下一个活动的正确内容选择。这是使用的意图完成

二,基于你作出决定你对ListActivity的previous活动传递的信息是什么,以及如何显示内容。

Second, based on the information passed by the previous activity you take decisions in your ListActivity about what and how to display the content.

这篇关于如何添加个人/相关名单按字母顺序排列的GridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:13