在我的代码中, 我创建了双名按钮。 当我创建多个按钮时, 问题如下 :
""https://i.sstatic.net/0wTti.jpg" alt="此处输入图像描述"/ >
扣子扣下来的时候我怎么弄得到?
我的代码:
private void showGlossary(String ContentTab) {
LinearLayout layout;
LinearLayout.LayoutParams p;
layout = (LinearLayout) findViewById(R.id.GlossaryTab1);
p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.FILL_PARENT
);
Glossary = (TextView) findViewById(R.id.glossary);
Glossary.setText("Glossário:");
while (ContentTab.indexOf("<gloss") != -1) {
ContentTab = ContentTab.substring(ContentTab.indexOf("<gloss"));
uri = ContentTab.substring(ContentTab.indexOf("<gloss") + 1, ContentTab.indexOf(">"));
Button myButton = new Button(this);
myButton.setText(Html.fromHtml(ContentTab.substring(ContentTab.indexOf(">") + 1, ContentTab.indexOf("</gloss>"))));
myButton.setLayoutParams(p);
myButton.setContentDescription(uri);
layout.addView(myButton);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
Toast.makeText(ShowPhytoterapicActivity.this, Html.fromHtml(getGlossaryItem(view.getContentDescription().toString())), Toast.LENGTH_LONG).show();
}
});
if(ContentTab.indexOf("</gloss>") != -1)
ContentTab = ContentTab.substring(ContentTab.indexOf("</gloss>") + 9);
}
}
我的XML:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/GlossaryTab1"
android:orientation="horizontal"
>
</LinearLayout>
有人能帮我吗?