gpt4 book ai didi

java - ListView 未正确填充/不可见

转载 作者:行者123 更新时间:2023-12-01 11:21:18 43 4
gpt4 key购买 nike

我有一个带有自定义列表适配器的 Activity 。如果填充 ListView 的数组列表为空,我会向用户显示一个文本框,否则文本框将变得不可见,并显示 ListView 。每当数组列表为空时,文本框都会出现,但是当它不是空时,我会得到一个空白屏幕。我不确定这是因为我的 ListView 不可见还是因为它没有正确填充。昨天这工作得很好,但从那以后我对类(class)做了很多改变,我不确定是哪一个导致了这个问题。在过去的几个小时里我一直在尝试遵循代码来解决这个问题,我注意到如果我在适配器的 getView() 方法中添加一个 log 调用,它不会显示,如果我将它添加到构造函数中,它会显示正常。我还确保适配器被调用并使用 log 在 if 语句中输入正确的条件。我希望你们中的一个人能够发现问题,而我却不能。

调用适配器的方法:

 private void PopulateLister(ArrayList<BetDisplayer> listwriterr) {
Log.d("POPULATING", listwriterr.toString());
if (listwriterr.isEmpty()) {
TextView emptybet = (TextView) findViewById(R.id.nobetstxtbox);
// emptybet.setText("None of your bets have been settled yet.");
emptybet.setVisibility(View.VISIBLE);
ListView listView = (ListView) findViewById(R.id.betslistviews);
listView.setVisibility(View.GONE);
}
else if (listwriterr.size() > 0){
TextView emptybet = (TextView) findViewById(R.id.nobetstxtbox);
emptybet.setVisibility(View.GONE);
ListView listView = (ListView) findViewById(R.id.betslistviews);
listView.setVisibility(View.VISIBLE);
if (listwriterr.get(0).getStatus().equals("open")){
ArrayAdapter<BetDisplayer> adapter = new MyListAdapter1();
listView.setAdapter(adapter);
}
else {
ArrayAdapter<BetDisplayer> adapter = new MyListAdapter2();
listView.setAdapter(adapter);
}



}
}

Activity 的 XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout23"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical">
<!-- Main ListView
Always give id value as list(@android:id/list)
-->
<fragment
android:id="@+id/fragment"
android:name="com.example.albert.betterapp.menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_menu" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:orientation="horizontal"
android:weightSum="100">

<LinearLayout
android:id="@+id/openbetslayout"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="49"
android:tag=""
android:background="@drawable/bettypeselector"
android:clickable="true">

<TextView
android:id="@+id/openbetstxtview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:clickable="false"
android:gravity="center"
android:text="Open Bets"
android:textColor="#B4B5AE"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/seperator">

</LinearLayout>

<LinearLayout
android:id="@+id/closedbetslayout"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="49"
android:tag=""
android:background="@drawable/bettypeselector"
android:clickable="true">

<TextView
android:id="@+id/settledbetstxtview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:clickable="false"
android:gravity="center"
android:text="Settled Bets"
android:textColor="#B4B5AE"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>


<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="fill_parent"
android:id = "@+id/displayallbetsrefresh"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:id="@+id/nobetstxtbox"
android:text="You currently don't have any open bets saved."
android:textStyle="bold"
android:layout_gravity="center"
android:gravity="center"
android:visibility="gone"
android:textSize="17sp"
android:textColor="#067103"/>
<ListView
android:id="@+id/betslistviews"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/betcolor"></ListView>
</android.support.v4.widget.SwipeRefreshLayout>


</LinearLayout>

适配器:

 private class MyListAdapter1 extends ArrayAdapter<BetDisplayer> {
public MyListAdapter1() {
super(DisplayAllBets.this, R.layout.activity_singletotalbet, openbetsarray);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d("TESTING", "123123123");
itemView = convertView;
if (itemView == null) {
itemView = getLayoutInflater().inflate(R.layout.activity_singletotalbet, parent, false);
}
Button v = (Button) itemView.findViewById(R.id.detailsbutton);
BetDisplayer currentwriter = openbetsarray.get(position);
Log.d("TESTING", currentwriter.getSelections());
Log.d("TESTING2", currentwriter.getSelections());
String selections = currentwriter.getSelections();
int numberofselections = 0;

for (int i = 0; i < selections.length(); i++) {
if (selections.charAt(i) == '/') {
numberofselections++;
}
}
if (numberofselections == 1) {
TextView descriptor = (TextView) itemView.findViewById(R.id.no);
descriptor.setText("Single");
} else if (numberofselections == 2) {
TextView descriptor = (TextView) itemView.findViewById(R.id.no);
descriptor.setText("Double");
} else if (numberofselections == 3) {
TextView descriptor = (TextView) itemView.findViewById(R.id.no);
descriptor.setText("Treble");
} else {
TextView descriptor = (TextView) itemView.findViewById(R.id.no);
descriptor.setText("Accumulator" + "(" + numberofselections + ")");
}
TextView status = (TextView) itemView.findViewById(R.id.status);
status.setText(currentwriter.getStatus());
Log.d("ERRORDEBUG", currentwriter.toString());
if (status.getText().toString().equals("open")) {
TextView winnings = (TextView) itemView.findViewById(R.id.winnings);
winnings.setText("-");
/*LinearLayout displaylayout = (LinearLayout) itemView.findViewById(R.id.displaylayout);
displaylayout.setBackgroundColor(Color.parseColor("#FFFFFF"));
Button b = (Button) itemView.findViewById(R.id.detailsbutton);
b.setBackgroundResource(R.drawable.btnback);*/
}
else if (status.getText().toString().equals("lost")) {
TextView winnings = (TextView) itemView.findViewById(R.id.winnings);
winnings.setText("0");
/*LinearLayout displaylayout = (LinearLayout) itemView.findViewById(R.id.displaylayout);
Button b = (Button) itemView.findViewById(R.id.detailsbutton);
b.setBackgroundResource(R.drawable.btnbacklost);
displaylayout.setBackgroundResource(R.drawable.lost);*/
}
else {
TextView winnings = (TextView) itemView.findViewById(R.id.winnings);
winnings.setText(Integer.toString(currentwriter.getReturns()));
/* Button b = (Button) itemView.findViewById(R.id.detailsbutton);
b.setBackgroundResource(R.drawable.btnback);
LinearLayout displaylayout = (LinearLayout) itemView.findViewById(R.id.displaylayout);
displaylayout.setBackgroundResource(R.drawable.won);*/
}
TextView winningss = (TextView) itemView.findViewById(R.id.winningss);
winningss.setText(Integer.toString(currentwriter.getReturns()));
TextView stakes = (TextView) itemView.findViewById(R.id.stakes);
stakes.setText(Integer.toString(currentwriter.getStake()));
TextView tokens = (TextView) itemView.findViewById(R.id.tokens);
tokens.setText(currentwriter.getId().substring(0,10));
TextView teams = (TextView) itemView.findViewById(R.id.teams);
TextView finalteams = (TextView) itemView.findViewById(R.id.actteams);
String userselectionssetter = currentwriter.getUserselections();
String actteamssetter = currentwriter.getActualselections();
teams.setText(userselectionssetter);
finalteams.setText(actteamssetter);
return itemView;


}
}

最佳答案

您的 SwipeRefreshLayout 有 2 个 subview ,如果我没记错的话,这会导致显示问题。你应该有类似的东西:

<SwipeRefreshLayout>
<FrameLayout>
<ScrollView>
<TextView/>
</ScrollView>
<ListView/>
</FrameLayout>
</SwipeRefreshLayout>

这是显示列表或文本时拉动刷新工作的唯一方法,然后您还必须重写 canChildScrollUp()。祝你好运。

否则,将文本放在 SwipeRefreshLayout 之外,并将 ListView 作为其唯一子级,但是当显示文本时,将无法进行滑动刷新。

关于java - ListView 未正确填充/不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31196544/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com