小编FET*_*FET的帖子

如何在RecyclerView中显示ArrayList?

我需要添加一个Activity我可以列出的元素,ArrayList<CustomClass>我已经看到有一种更新,更好的方式来显示列表 - RecyclerView.

我的问题是如何将此实现到我的应用程序中.我发现我需要使用Adapter,但我不太明白如何正确实现整个过程.

如果你想知道,我指的是这个的文档的例子,这是我一直在读.

编辑:

更新了我的代码后,它说它无法解析符号setOnEntryClickListener:

public class voting extends Activity {


RecyclerView myList;
private ArrayList<Player> players; // Players


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

    Intent intent = this.getIntent();
    Bundle bundle = intent.getExtras();
    players = (ArrayList<Player>)bundle.getSerializable("PLAYERS");

    myList = (RecyclerView) findViewById(R.id.charactersList);
    myList.setLayoutManager(new LinearLayoutManager(this));
    CoursesAdapter adapter = new CoursesAdapter(players);
    myList.setAdapter(adapter);
}

// OR RecyclerView with a click listener

CoursesAdapter clickAdapter = new CoursesAdapter(players);
clickAdapter.setOnEntryClickListener(new CoursesAdapter.OnEntryClickListener() {
    @Override
    public …
Run Code Online (Sandbox Code Playgroud)

java android arraylist android-adapter android-recyclerview

10
推荐指数
1
解决办法
3万
查看次数

如何使用StartActivityForResult()

在我的应用程序中,我需要快速 询问用户input.

我需要从这个 Flash-Activity 获得一个结果,然后回到上一个.

我已经读过这个StartActivityForResult()方法,但我还不确定如何正确使用它,任何例子?

编辑:

我试图通过intent(作为结果)使用我在应用于StartActivityForResult()的此方法的所有应用程序中使用的方法传递Player对象:

在我的第二个Activity(我需要得到结果的那个):

Intent intent = new Intent();
Player playerKilled = players.get(position);

Bundle bundle = new Bundle();
bundle.putSerializable("PLAYER_KILLED", (Serializable) playerKilled);
intent.putExtras(bundle);

setResult(Activity.RESULT_OK, intent);
finish();
Run Code Online (Sandbox Code Playgroud)

我的主要活动,我需要将结果带到:

if (resultCode == Activity.RESULT_OK) {

    Intent intent = this.getIntent();
    Bundle bundle = intent.getExtras();
    playerKilled = (Player)bundle.getSerializable("PLAYER_KILLED");

    Toast.makeText(this, playerKilled.getName() + "the " + playerKilled.getCardName() + " has died, and he/she had the ID: " + playerKilled.getId(), Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)

android android-fragments

7
推荐指数
1
解决办法
3万
查看次数

在Java中传递引用

我有这个纸牌游戏,我将所有玩家存储在一个List.为了找出我想与谁一起行动的玩家,每个玩家都有一个Card(我可以得到卡片名称),a name(我可以得到玩家的名字),但每个玩家都有一个独特的ID.

现在,在我的onCreate()方法开始时,我找到并将列表的播放器分配给播放器Player clairvoyant:

public void initializeCharacters() {
    for (Player player : players) {
        if (player.getCardName().equals("Clairvoyant")) {
            clairvoyant = player;
        }
}
Run Code Online (Sandbox Code Playgroud)

游戏在夜晚和白天之间切换.透视力的转折是在夜间,我用一个开关来确定何时轮到谁.

现在,在开始千里眼之前,我会检查他是否还活着,在否定的情况下,我只是跳过他的回合:

case 2:
                    clairvoyant(); // Clairvoyant's turn
                    Toast.makeText(Game.this, String.valueOf(clairvoyant.getLifeStatus()), Toast.LENGTH_SHORT).show();
                    if(clairvoyant.getLifeStatus()) {
                    /* --- Let him choose ---*/
                        Intent intent = new Intent(this, ListPlayersClairvoyant.class);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("PLAYERS", (Serializable) players);
                        intent.putExtras(bundle);
                        startActivityForResult(intent, REQUEST_CLAIRVOYANT);
                    /* --------------------- */
                    }
                    nightInsideCounter++;
                    if(medium == null) {
                        nightInsideCounter++;
                    } …
Run Code Online (Sandbox Code Playgroud)

java android

6
推荐指数
1
解决办法
573
查看次数

Android-更改ListView特定项目的背景颜色

我正在制作一款游戏,它将使用Listview来显示一些文本作为聊天记录。

其中一些文本表示事件,因此我想根据该特定事件(例如EX)更改其背景颜色。有人被杀,该特定Listview物品的背景颜色为红色

我该如何实现?

这是我的JAVA代码:

            //STARTING SETUP
        ArrayList<String> arrayListMother;
        ArrayAdapter<String> arrayAdapterMother;
        ListView listViewMother;

        int counter;
        boolean introDone = false;

        String[] night = {"Welcome!","This is Lupus In Tabula!","You're gonna experience the Hasbro Game in a total new way, have fun!"};
        String[] day = {"Thank you!","Great","Let's do it!"};
        String[] dead = {"Thank you!","Great","Let's do it!"};
        String[] saved = {"Thank you!","Great","Let's do it!"};

        Button buttonGo;
        //ENDING SETUP


        //CREATE - CREATE//
        @Override
        protected void onCreate(Bundle savedInstanceState) { …
Run Code Online (Sandbox Code Playgroud)

android listview android-listview

3
推荐指数
2
解决办法
1万
查看次数

ndigit[c - '0'] 的清晰解释

我终于开始阅读K&R,并且刚刚到达数组部分。但是在本节的示例中,有一段代码我真的不完全理解,所以我想请您对其进行清楚的解释,因为我想理解C的每个概念,因为我知道这是基础快速学习 C++。

顺便说一句,我已经对 JAVA 有一定的了解,希望这对您的解释设置有所帮助。

问题:

在这段代码中ndigit[c - '0'],我不明白它想要做什么,我从其他 Stack Overlfow 问题中知道 0 应该引用 ASCI标准并且应该是48,但仍然不明白 c 和 0 有什么关系

c arrays

2
推荐指数
1
解决办法
998
查看次数

如何在布局中的任何视图上添加灰色叠加

我想知道如何为布局文件中的所有内容添加灰色覆盖,以便查看布局中的所有内容,但是启用了该灰色透明覆盖。

我试图将a View设置为backgroundlike #80000000,但是看起来这View 占用了所有空间LinearLayout实际上我在使用a )。

相反,我希望此覆盖层覆盖所有其他视图,但仍然希望能够看到其背后的内容

android

0
推荐指数
1
解决办法
1092
查看次数