Java 如何从弹出窗口接受用户输入?
我是android新手,刚刚处于学习阶段,有一个问题,如果你能回答,那就太好了 我尝试制作的第一个应用程序是关于计算分数的,它还有一个记分板页面,显示哪个球员得分多少。我想做的是在运行时接受玩家的名字,可能使用弹出窗口,一旦玩家1退出,再次弹出窗口以获取第二个玩家的名字 代码如下: 活动记分牌:Java 如何从弹出窗口接受用户输入?,java,android,Java,Android,我是android新手,刚刚处于学习阶段,有一个问题,如果你能回答,那就太好了 我尝试制作的第一个应用程序是关于计算分数的,它还有一个记分板页面,显示哪个球员得分多少。我想做的是在运行时接受玩家的名字,可能使用弹出窗口,一旦玩家1退出,再次弹出窗口以获取第二个玩家的名字 代码如下: 活动记分牌: <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android="http://schemas.android.com/a
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list_of_players"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.cricketcounter.Scoreboard">
</ListView>
PlayerAdapter.java:
package com.example.android.cricketcounter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by Abhijeet on 01-07-2017.
*/
public class PlayerAdapter extends ArrayAdapter<Players> {
public PlayerAdapter(Context context, ArrayList<Players> players){
super(context, 0, players);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
Players currentPlayer = getItem(position);
TextView playerName = (TextView) listItemView.findViewById(R.id.name);
playerName.setText(currentPlayer.getPlayerName());
TextView runsScored = (TextView) listItemView.findViewById(R.id.runsA);
runsScored.setText(String.valueOf(currentPlayer.getRuns()));
TextView ballsTaken = (TextView) listItemView.findViewById(R.id.ballsA);
ballsTaken.setText(String.valueOf(currentPlayer.getBalls()));
return listItemView;
}
}
package com.example.android.cricketcounter;
导入android.content.Context;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ArrayAdapter;
导入android.widget.TextView;
导入java.util.ArrayList;
/**
*由阿比吉特于2017年7月1日创建。
*/
公共类PlayerAdapter扩展了ArrayAdapter{
公共玩家适配器(上下文、ArrayList玩家){
超级(上下文,0,玩家);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
View listItemView=convertView;
如果(listItemView==null){
listItemView=LayoutFlater.from(getContext()).inflate(
R.layout.list_项,父项,false);
}
玩家currentPlayer=getItem(位置);
TextView playerName=(TextView)listItemView.findViewById(R.id.name);
playerName.setText(currentPlayer.getPlayerName());
TextView runsCord=(TextView)listItemView.findViewById(R.id.runsA);
runsScored.setText(String.valueOf(currentPlayer.getRuns());
TextView-ballsTaken=(TextView)listItemView.findViewById(R.id.ballsA);
setText(String.valueOf(currentPlayer.getBalls());
返回listItemView;
}
}
取决于您如何使用Popuscure,这是一种方法,->当玩家离开时,dialogbox获取玩家姓名->根据需要将该姓名存储在数据库列表中,然后notifyDataSetChanged()
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/runsA"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ballsA"/>
</LinearLayout>
package com.example.android.cricketcounter;
/**
* Created by Abhijeet on 01-07-2017.
*/
public class Players {
private String mPlayerName;
private int mRuns;
private int mBalls;
public Players(String playerName, int runs, int balls){
mPlayerName = playerName;
mRuns = runs;
mBalls = balls;
}
public String getPlayerName(){
return mPlayerName;
}
public int getRuns(){
return mRuns;
}
public int getBalls() {
return mBalls;
}
}
package com.example.android.cricketcounter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by Abhijeet on 01-07-2017.
*/
public class PlayerAdapter extends ArrayAdapter<Players> {
public PlayerAdapter(Context context, ArrayList<Players> players){
super(context, 0, players);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
Players currentPlayer = getItem(position);
TextView playerName = (TextView) listItemView.findViewById(R.id.name);
playerName.setText(currentPlayer.getPlayerName());
TextView runsScored = (TextView) listItemView.findViewById(R.id.runsA);
runsScored.setText(String.valueOf(currentPlayer.getRuns()));
TextView ballsTaken = (TextView) listItemView.findViewById(R.id.ballsA);
ballsTaken.setText(String.valueOf(currentPlayer.getBalls()));
return listItemView;
}
}