導航:首頁 > 操作系統 > android動態建textview

android動態建textview

發布時間:2022-06-14 02:13:11

android動態添加自定義TextView後如何更新某一個TextView的內容

public class MainActivity extends Activity { private int index; private TextView mTextView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mTextView = new TextView(this); setContentView(mTextView); new DataThread().start(); } private String getWebData() { return String.valueOf(++index); } private Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { mTextView.setText((String)msg.obj); }; }; private class DataThread extends Thread { @Override public void run() { for(int i = 0; i < 4; i++) { try { Thread.sleep(1000); } catch (InterruptedException e) { } final String data = getWebData(); // 只能在主線程中修改ui控制項 mHandler.sendMessage(mHandler.obtainMessage(0, data)); } } } }

Ⅱ android動態創建的Textview怎麼獲取或者給他設置一個ID

ID本身是個int類型的,就算設置也只能給一個隨機不重復的int數字,但是如果想要通過字元串去實現,用個HashMap把鍵值對存下來

final static HashMap<String, Integer> listView = new HashMap<String, Integer>();

賦值ID linearLayout.setId(唯一id);

鍵值對 listView.put(字元串id, 前邊定義的唯一int ID);

獲取:

public static Integer getViewIdById(String id){
if (listView.containsKey(id))
return listView.get(id);
else
return -1;
}

Ⅲ android怎麼用java代碼動態給layout的textview設置text

1 <TextView android:id="@+id/Title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:drawableRight="@drawable/check_down" android:gravity="center_vertical" android:textSize="24dip" android:maxLines="1" android:ellipsize="end"/> 我們寫在xml的時候,都是這么寫的。那代碼呢?我們發現TextView他有一個方法 2 public void setCompoundDrawables (Drawable left, Drawable top, Drawable right, Drawable bottom); 這個方法呢,就是可以在Java代碼動態的畫 左上右下幾個方向 類似於xml中的 android:drawableLeft="@drawable/icon" android:drawableTop="@drawable/icon" android:drawableRight="@drawable/icon" android:drawableButtom="@drawable/icon" 3 具體在代碼中的用法是: Drawable drawable = getResources().getDrawable(R.drawable.spinner_checked); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //設置邊界 titleTv.setCompoundDrawables(null, null, drawable, null);//畫在右邊 4 運行之後的效果 如何在代碼中動態為TextView設置drawableRight 如何在代碼中動態為TextView設置drawableRight 5 界面比較丑,勿噴,大家也還可以通過這個方法實現 public void (Drawable left, Drawable top, Drawable right, Drawable bottom)

Ⅳ android動態添加textview

你沒設置文字顏色吧

tv.setTextColor(this.getResources().getColor(R.color.black));
強制給設個顏色,不然系統自己默認個給你顯示,有的版本系統默認白色有的黑色。我之前就遇到過,在2.3.3系統上顯示黑色,在4.0.0系統顯示白色

Ⅳ 安卓在TableLayout中使用動態創建TextView,界面不顯示,是為什麼

必須
原我猜測
面textview設置寬高度自適應 wrap-content

文字通代碼態寫入所自

應該新手吧
基本android布局知識

Ⅵ Android,在LinearLayout中動態添加TextView,幾點疑問

第一條:
是可以在xml中定義text的,比如定義textview layout文件如下:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:textSize="@dimen/textsize"
android:ellipsize="end"
android:layout_height="@dimen/height_22">
</TextView>

那麼在代碼里可以用inflater把該xml化成view,寫法大致如下:
TextView text1 = (TextView) inflater.inflate(this, R.layout.text, null);

第二條:
兩個text佔一行的實現方式就多了,
比如可以在xml中把兩個textview 放在一個horizontal的linearLayout中,或是使用 RelativeLayout放在同一行即可,關鍵是控制好兩個textview都不換行就行。

第三條:
分割線的實現方式也有幾種。
比如兩個textview控制項中有個imageview控制項,imageview用線的圖片。
或者用textview的drawableLeft drawableRight屬性,把圖片設置成前一個textview的drawableRight或是設置成後一個textview的drawableLeft,線使用圖片或者自己定義都可以的。

Ⅶ android中使用ArrayAdapter如何讓ListView中動態添加TextView控制項

餓。。
我沒明白你的意思。
android.app.Activity這個類是不能直接設置Adapter的,
如果你想在一個Activity中直接設置Adapter,
可以用ListActivity.
這個類是Activity的子類,
所以Activity有的功能它都有,並接它還有ListView的功能,
你可以在這個Activity中直接通過this.setListAdapter(adapter);方法來為這個Activity設置Adapter。
另外,虛機
團上
產品團購,超級便宜

Ⅷ Android 的RelativeLayout 布局中動態添加TextView,並且設置該TextView在另外一個TextView的右邊。

先用一個TextView獲得你的基準控制項的id,這樣這個TextView就是那個基準控制項了,然後新建一個TextView在後面找庫函數,設置在基準控制項的右邊就行了,最後別忘了加上contentView函數

Ⅸ android中將通知的信息保存在動態生成的textview中並加在原有layout中,textview為何只能生成一個

可以生成多個textView的,如果你需要的話。

TextView textView = new TextView(this);
//TODO
layout.addView(textView );
TextView textView = new TextView(this);
TextView textView2 = new TextView(this);
//TODO
layout.addView(textView );
layout.addView(textView2 );

Ⅹ 求高手指點,android動態生成一組TextView,怎樣判斷點擊了那個TextView

如果你確定你的代碼沒問題的話,

不妨試試自己定義一個
class MTextView extends TextView{
int id;
MTextView MTextView(int id){

super.TextView(context);
this.id=id;
}
int getId(){}
void setId(int id){}
}

閱讀全文

與android動態建textview相關的資料

熱點內容
安卓手機的動態照片為什麼卡 瀏覽:538
ad編譯集成庫時最常見的問題 瀏覽:845
matlab微分方程編程 瀏覽:699
安卓手機如何打開esp文件 瀏覽:545
什麼app能安裝應用 瀏覽:199
手機用什麼app看電視劇電影好 瀏覽:603
導入原理圖為什麼文件夾不顯示 瀏覽:653
androidapp風格 瀏覽:209
php取伺服器url地址 瀏覽:293
linux時間調度演算法 瀏覽:769
單片機最小電路詳解 瀏覽:185
請求要求命令 瀏覽:806
電腦文件夾發微信顯示被佔用 瀏覽:295
手機怎麼看加密視頻 瀏覽:206
怎樣解壓手機es文件包 瀏覽:661
2017年學什麼編程 瀏覽:935
金融期貨pdf 瀏覽:694
程序員客棧的信息保密嗎 瀏覽:507
編程顯示器什麼意思 瀏覽:147
網路編程的就業 瀏覽:260