-3

在我的 android 应用程序(几乎完成)中,我有一个列表视图来显示作弊码的名称,当用户单击名称时,我希望文本更改
例如:
之前 - 点击我
之后 - 你点击我
我不确定是否我这样做是正确的,如果 OnClick 弹出窗口更容易,任何链接或评论/答案都会受到高度评价


谷歌寻找以下关键字,但结果没有给我我正在寻找的东西

“Android Listview”、“Android Listview popup”、“Android Listview Onclick”、“Listview Onclick”、“点击时改变android应用文本”、“点击时改变android listview结果”


作弊码.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:background="@drawable/app_bg"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >

<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="20sp" >
</TextView>

</RelativeLayout>

作弊码.java

package grand.theft.auto.v;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class CheatCodes extends ListActivity {

static final String[] Cheatcodes = new String[] { "Wanted Level Up", "Wanted Level Down", "Recharge Ability",
        "Fast Run", "Fast Swim", "Parachute", "Explosive Punch", "Flaming Bullets",
        "Slow Motion Aim", "Sky Fall", "Buzzard Attack Helicopter",   "Comet", "Sanchez", "Trash Master",
        "Limo", "Stunt Plane", "PCJ-600", "Caddy", "Rapid GT", "Duster"};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    setListAdapter(new ArrayAdapter<String>(this,  R.layout.cheatcodes,Cheatcodes));

    ListView listView = getListView();
    listView.setTextFilterEnabled(true);

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // When clicked, show a toast with the TextView text
            Toast.makeText(getApplicationContext(),
            ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
    });

}

}
4

1 回答 1

1

在 onItemClick 中试试这个:

CharSequence text= (CharSequence) parent.getItemAtPosition(pos);
//This is where you change the text to show
text = "You " + text;
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
//If you want to update the listview
Cheatcodes[pos] = text;
于 2013-09-23T01:51:52.630 回答