listview中的每一行都有2个按钮。要显示的文本取决于某些特征,因此我想更改Button上的文本。但是,我不仅无法更改文本,而且显示的文本就像按钮的内部地址,即" ANDROID.WIDGET.BUTTON {175F420 VFED..C .. ....我。 0,0-0,0#7F0C00083 APP:ID / READ}这是我的代码:
import android.widget.Button;
....
public void ShowArticles(){
ArrayList<ArticleSelection> articleSelectionList = helper
.GetArticleListForResource(globalVariable.getCategoryIndex());
String[] columnNames = {"_id", "Column1", "Column2", "Column3",
"Column4", "Column5", "Column6", "Column7"};
MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id",
"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7" });
int[] to = new int[]{R.id.id, R.id.imageButton, R.id.title, R.id.year, R.id.authors,
R.id.favs, R.id.read, R.id.readOnLine};
for (ArticleSelection articleItem : articleSelectionList) {
Button btn1 = (Button) ThisView.findViewById(R.id.read);
Button btn2 = (Button) ThisView.findViewById(R.id.readOnLine);
if (Downloaded == "Y"){
btn1.setText("Read");
}
else btn1.setText("Download");
matrixCursor.addRow(new Object[]{k, imgFile,Title, Year , Authors, favs , btn1, btn2 });
}
SimpleCursorAdapter menuItems = null;
menuItems = new SimpleCursorAdapter(
this, R.layout.article_row, matrixCursor, columnNames, to);
listView.setAdapter(menuItems);
}
我的按钮XML:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/read"
android:backgroundTint="#00000000"
android:text="Download"
android:layout_toRightOf="@+id/favs"
android:layout_alignBottom="@+id/imageButton"
android:layout_marginStart="11dp"
android:layout_weight="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id = "@+id/readOnLine"
android:backgroundTint="#00000000"
android:layout_toRightOf="@+id/read"
android:text="Read Online"
android:layout_alignBottom="@+id/imageButton"
android:layout_alignParentEnd="true"
android:layout_weight="1"
/>
谢谢。答案可能很简单,因为我之前已经这样做了,但我不认为我已经在一系列列表视图中完成了它。 我已经看到了关于向按钮添加文本的其他答案,以及我尝试过的那些。
答案 0 :(得分:1)
首先在for循环之外声明你的Button
Button btn1 = (Button) ThisView.findViewById(R.id.read);
Button btn2 = (Button) ThisView.findViewById(R.id.readOnLine);
在String
使用equals
而不是==
Downloaded.equals("Y");
第三,ANDROID.WIDGET.BUTTON{175F420 VFED..C.. ....I. 0,0-0,0#7F0C00083 APP:ID/READ
是btn1
答案 1 :(得分:1)
尝试将添加行更改为
<asp:GridView Runat="server" id="gv1" PageSize="20" Visible="False" AllowPaging="True" Width="100%"
CssClass="clsDataGrid" AutoGenerateColumns="false" DataKeyNames="intProofSLNo,txtAdminRemarks" CommandArgument='Eval(intProofSLNo,txtAdminRemarks)'
OnRowCommand="gv1_RowCommand" OnRowDataBound ="gv1_OnRowDataBound" >
<asp:BoundField DataField="intProofSLNo" ReadOnly="True" Visible="false" ItemStyle-Wrap="false" HeaderText="Sl No" ItemStyle-CssClass="clsNormalText"></asp:BoundField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="lnkbtnApprove" runat="server" CommandName="Approve" Text= "Approve / " />
<asp:LinkButton ID="lnkbtnReject" runat="server" CommandName="Reject" Text= "Reject" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Admin Remarks">
<ItemTemplate>
<asp:Label ID="lblAdminRemarks" runat="server" ItemStyle-Wrap="True" Text='<%# Bind("txtAdminRemarks")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAdminRemarksEdit" runat="server" cssclass=clsCommonInput MaxLength="252" Text='<%# DataBinder.Eval(Container.DataItem, "txtAdminRemarks")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:LinkButton ID="lblEdit" runat="server" Text="Edit" ToolTip="Edit" CommandName="Edit" CommandArgument='<%# Container.DataItemIndex %>'>
</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdate" Width="38" runat="server" Text="Update|" CommandName="Update"CommandArgument='<%# Container.DataItemIndex %>' CausesValidation="true" ToolTip="Save"> </asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" Width="40" Text="Cancel" CommandName="Cancel"
CausesValidation="false" ToolTip="Reset"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>