我正在使用ArrayAdapter
和ListView
的字符串类型列表android.R.simple_list_view1;
但它没有更新。
package com.pratham.cricket1;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
public TextView t1,t2;
String over_format;
public int ta,tb;
public String inning;
public int w1,w2,extras;
public int balls,w,t,ballsc,target,innings;
LinearLayout l1,l2,l11,l22,outercover1,outercover2,big;
ListView hj;
ArrayList<String> a;
ArrayAdapter<String> m;
View v1;
TextView g1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
big=(LinearLayout)getLayoutInflater().inflate(R.layout.activity_main,null,false);
setContentView(big);
over_format="";
l1= (LinearLayout)getLayoutInflater().inflate(R.layout.teamabatting,null,false);
l2=(LinearLayout)getLayoutInflater().inflate(R.layout.teambbatting,null,false);
outercover1=(LinearLayout)big.findViewById(R.id.outer_cover1);
outercover2=(LinearLayout)big.findViewById(R.id.outer_cover2);
a=new ArrayList<String>();
m=new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,a);
v1=(LinearLayout)getLayoutInflater().inflate(R.layout.bowling,null,false);
hj=v1.findViewById(R.id.overs);
hj.setAdapter(m);
innings=1;
Intent i2=getIntent();
Bundle b2=i2.getExtras();
if(!b2.isEmpty()){
balls=b2.getInt("Balls");
t=b2.getInt("Team won toss");
w=b2.getInt("Winning team chose");
}else{}
extras=0;
ta=0;
ta=0;
w1=0;
w2=0;
t1=l1.findViewById(R.id.TeamA);
t2=l2.findViewById(R.id.TeamB);
l11=l1;
l22=l2;
ballsc=balls;
TeamABatting();
}
public void a1(View view){
balls--;
score_add(1,t1);
checkInningsEnd(balls);
make_over_format(1,balls);
}
public void a2(View view){
balls--;
score_add(2,t1);
checkInningsEnd(balls);
make_over_format(2,balls);
}
public void a3(View view){
balls--;
score_add(3,t1);
checkInningsEnd(balls);
make_over_format(3,balls);
}
public void a4(View view){
balls--;
score_add(4,t1);
checkInningsEnd(balls);
make_over_format(4,balls);
}
public void a6(View view){
balls--;
score_add(6,t1);
checkInningsEnd(balls);
make_over_format(6,balls);
}
public void b1(View view){
balls--;
score_add(1,t2);
checkInningsEnd(balls);
make_over_format(1,balls);
}
public void b2(View view){
balls--;
score_add(2,t2);
checkInningsEnd(balls);
make_over_format(2,balls);
}
public void b3(View view){
balls--;
score_add(3,t2);
checkInningsEnd(balls);
make_over_format(3,balls);
}
public void b4(View view){
balls--;
score_add(4,t2);
checkInningsEnd(balls);
make_over_format(4,balls);
}
public void b6(View view){
balls--;
score_add(6,t2);
checkInningsEnd(balls);
make_over_format(6,balls);
}
public void score_add(int a ,TextView t3){
if(t3==findViewById(R.id.TeamA)){
ta+=a;
Score_doner(t3,ta,w1,balls);
}
if(t3==findViewById(R.id.TeamB)){
tb+=a;
Score_doner(t3,tb,w2,balls);
}
}
public void TeamAOut(View view){
balls--;
w1++;
Score_doner(t1,ta,w1,balls);
checkInningEnd(w1);
checkInningsEnd(balls);
make_over_format(7,balls);
}
public void TeamBOut(View view){
balls--;
w2++;
Score_doner(t2,tb,w2,balls);
checkInningEnd(w2);
checkInningsEnd(balls);
make_over_format(7,balls);
}
public void Score_doner(TextView t4,int runs,int wicket,int b){
t4.setText(Integer.toString(runs)+"/"+Integer.toString(wicket));
g1.setText(Integer.toString(b));
}
public void TeamABatting(){
outercover1.removeAllViews();
outercover1.addView(l11);
outercover2.removeAllViews();
View v1=(LinearLayout)getLayoutInflater().inflate(R.layout.bowling,null,false);
outercover2.addView(v1);
if(innings==2){
TextView t8=v1.findViewById(R.id.target);
t8.setText(Integer.toString(ta));
}else{
inning="1b";
}
g1=v1.findViewById(R.id.ballsleft);
g1.setText(Integer.toString(balls));
}
public void TeamBBatting(){
outercover2.removeAllViews();
outercover2.addView(l22);
outercover1.removeView(l1);
View v1=getLayoutInflater().inflate(R.layout.bowling,null);
outercover1.addView(v1);
if(innings==2){
TextView t8=v1.findViewById(R.id.target);
t8.setText(Integer.toString(ta));
}else{
inning="1a";
}
g1=v1.findViewById(R.id.ballsleft);
balls=ballsc;
g1.setText(Integer.toString(balls));
}
public void AExtras(View view){
extras++;
score_add(1,t1);
}
public void BExtras(View view){
score_add(1,t2);
}
public void Adots(View view){
balls--;
score_add(0,t1);
checkInningsEnd(balls);
make_over_format(0,balls);
}
public void Bdots(View view){
balls--;
score_add(0,t1);
checkInningsEnd(balls);
make_over_format(0,balls);
}
public void checkInningEnd(int a){
if(innings!=2) {
if (a == 10 && w1 == 10) {
balls=ballsc;
innings = 2;
inning="2a";
TeamBBatting();
} else if (a == 10 && w2 == 10) {
balls=ballsc;
innings = 2;
inning="2b";
TeamABatting();
}
}else if(a==10&&w1==10&&w2==10){
Intent i1=new Intent(this,Main2Activity.class);
startActivity(i1);
}
}
public void checkInningsEnd(int b){
if(b==0&&inning=="1a"){
balls=ballsc;
innings = 2;
inning="2b";
TeamABatting();
}else if(b==0&&inning=="1b"){
balls=ballsc;
innings = 2;
inning="2a";
TeamBBatting();
}else if(b==0&&(inning=="2a"|| inning=="2b")){
Intent i1=new Intent(this,Main2Activity.class);
startActivity(i1);
}
}
public void make_over_format(int ak,int vb){
Log.e("Is it comming", "make_over_format: " );
if(vb%6!=0){
over_format+=" "+Integer.toString(ak);
}else{
a.add(over_format);
Log.e("The value of over:", "make_over_format: "+m.getItem(0) );
m.notifyDataSetChanged();
over_format="";
}
}
}
我该怎么办?
我的代码有什么问题?
是因为我正在从view
文件中膨胀layout
吗?
从另一个activity
调用activity
它没有给出任何错误。我不明白。
listview
未更新且完全空白