亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將 TableRow(代碼生成的)表的內容與字符串進行比較?

如何將 TableRow(代碼生成的)表的內容與字符串進行比較?

夢里花落0921 2021-12-22 20:42:21
所以我一直在嘗試這樣做,它基本上說我試圖獲得的“內容”為空。這是我正在測試的代碼(注釋部分是我試圖讓它工作的實際代碼,我只是添加了 println 以查看獲取的數據是否正確,事實并非如此)public void FiltarBusqueda(String filtro) {    int count=0;    for (int r = 0; r < mTableLayout.getChildCount(); r++) {        TableRow trow = (TableRow) mTableLayout.getChildAt(r);        for(int c=0;c <= trow.getChildCount();c++){            System.out.println(""+trow.getChildAt(c));            /*if (trow.getChildAt(c).toString() != filtro) {                count++; }            if(count==3){                mTableLayout.removeView(trow); }*/            }    }}public void onClickFiltro(View v){    EditText filtro = (EditText)findViewById(R.id.txtproducto);    FiltarBusqueda(filtro.getText().toString());}*此外,為每個創建 tablerows 的東西在同一個類中 *LinearLayout Thing:final LinearLayout layCustomer = new LinearLayout(this);            layCustomer.setOrientation(LinearLayout.VERTICAL);            layCustomer.setPadding(0, 10, 0, 10);            layCustomer.setBackgroundColor(Color.parseColor("#f8f8f8"));            final TextView tv3 = new TextView(this);            if (i == -1) {                tv3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,                        TableRow.LayoutParams.MATCH_PARENT));                tv3.setPadding(5, 5, 0, 5);                tv3.setTextSize(TypedValue.COMPLEX_UNIT_PX, smallTextSize);            } else {                tv3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,                        TableRow.LayoutParams.MATCH_PARENT));                tv3.setPadding(5, 0, 0, 5);                tv3.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);            }
查看完整描述

1 回答

?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

TextView#toString()不會在該 TextView 中獲取文本。它只打印類名和實例哈希碼。您需要使用TextView#getText()#toString().


用這個:


public void FiltarBusqueda(String filtro) {

    for (int r = 0; r < mTableLayout.getChildCount(); r++) {

        TableRow trow = (TableRow) mTableLayout.getChildAt(r);


        boolean hasMatch = false;


        for (int c = 0; c <= trow.getChildCount(); c++) {

            String text = ((TextView) trow.getChildAt(c)).getText().toString();


            hasMatch = text.equals(filtro); //when comparing Strings, use `equals()` not `==`

            if (hasMatch) break;

        }


        if (!hasMatch) {

            mTableLayout.removeRow(trow);

        }

    }

}


查看完整回答
反對 回復 2021-12-22
  • 1 回答
  • 0 關注
  • 170 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號