本文介绍了在Android的部分大胆的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要大胆的每一行的第一个字。但是,而不是勇于它显示了整个code!
I want to bold the first word of each line. But rather then being bold it shows entire code!
private void addAsimA(ArrayList<String> products) {
products.add("<b>Apple</b> It is red");
products.add("<b>Banana</b> It is yellow");
products.add("<b>Mango</b> It is green");
我怎样才能得到这样的输出:
How can I get output like this:
苹果公司这是红色的
香蕉这是黄
芒果这是绿色
下面是完整的Java文件
Here is the full java file
public class MainActivity extends Activity {
TextView txtv, txt1;
ImageView imgv;
// List view
private ListView lv;
// Listview Adapter
ArrayAdapter<String> adapter;
// ArrayList for Listview
ArrayList<HashMap<String, String>> productList;
ArrayList<String> products = new ArrayList<String>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addAsimA(products);
addAsimB(products);
}
private void addAsimA(ArrayList<String> products) {
products.add("<b>Apple</b> It is red");
products.add("<b>Banana</b> It is yellow");
products.add("<b>Mango</b> It is green");
}
private void addAsimB(ArrayList<String> products) {
products.add("<b>Flower</b> It is nice");
products.add("<b>Fog</b> It is white");
products.add("<b>Rose</b> It is pink");
lv = (ListView) findViewById(R.id.list_view);
// your code is added here but what is the problem?
TextView txt1 = (TextView) findViewById(R.id.product_list);
txt1.setText(Html.fromHtml(products.get(productList)));
// Adding items to listview
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_list, products);
lv.setAdapter(adapter);
}
}
有关文本视图的XML文件是在这里:
XML file for text view is here:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- Product Name -->
<com.examdple.customproduct.CustomTextView
android:textColor="?android:textColorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4sp"
android:id="@+id/product_list"
android:paddingLeft="20sp"
android:paddingBottom="2sp"
android:textSize="15sp" />
</LinearLayout>
如果有人要的文件: http://www.mediafire.com/?op37c1itodd8724
推荐答案
这样的:
TextView txt = (TextView) findViewById(R.id.myTxtV);
txt.setText(Html.fromHtml(products.get(index)));
这篇关于在Android的部分大胆的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!