2017-12-01 7 views
-2

自分自身のレイアウトを持つ「activityCatalog」があり、この中に別のレイアウトの魔法使いがリストアイテムのレイアウトとして表示されます。 リスト項目のレイアウトには、テキストビューとボタンがあります。 "activityCatalog"からこのボタンを使用してリスト項目のテキストビューを変更しようとしましたが、nullポインタ例外が返されます。他のレイアウトのテキストビューのテキストを変更する

アイデア? すべての質問

アダプタを掲載: パブリッククラスProductCursorAdapterは、CursorAdapterを{

public ProductCursorAdapter(Context context, Cursor c) { 
    super(context, c, 0); 
} 

@Override 
public View newView(Context context, Cursor cursor, ViewGroup parent) { 

    return LayoutInflater.from(context).inflate(R.layout.list_item, parent,false); 
} 


@Override 
public void bindView(View view, Context context, Cursor cursor) { 

    TextView nameTextView = (TextView) view.findViewById(R.id.name); 
    TextView priceTextView = (TextView) view.findViewById(R.id.price); 
    TextView quantityTextView = (TextView) view.findViewById(R.id.quantity); 
    TextView idTextView = (TextView) view.findViewById(R.id.Id_View); 

    // Find the columns of pet attributes that we're interested in 
    int nameColumnIndex = cursor.getColumnIndex(ProductEntry.COLUMN_NAME); 
    int priceColumnIndex = cursor.getColumnIndex(ProductEntry.COLUMN_PRICE); 
    int quantityColumnIndex = cursor.getColumnIndex(ProductEntry.COLUMN_QUANTITY); 
    int idColumnIndex = cursor.getColumnIndex(ProductEntry._ID); 

    // Read the pet attributes from the Cursor for the current pet 
    String Name = cursor.getString(nameColumnIndex); 
    String Price = cursor.getString(priceColumnIndex); 
    String quantity = cursor.getString(quantityColumnIndex); 
    String id = cursor.getString(idColumnIndex); 

    // Update the TextViews with the attributes for the current pet 
    nameTextView.setText(Name); 
    priceTextView.setText(Price); 
    quantityTextView.setText(quantity); 
    idTextView.setText(id); 
} 

} 
+0

次のようなリストビュー項目にアクセスすることはできません。それをアダプタで行います。 – ADM

+0

あなたの完全なコードを投稿して、明確に質問してください – Raja

+0

私はアダプタでそれをしましたが、私はボタンにアクセスするために正確に知りません。 –

答えて

0

this.YouアダプタgetViewメソッド(で実行する必要があるようにあなたは、ListView項目にアクセスすることはできません)を拡張。

public void bindView(View view, Context context, Cursor cursor) { 
Button button = (Button) view.findViewById(R.id.button); 
button.setOnClickListener(new OnClickListener() { 
    public void onClick(View v) { 
     //... 
    } 
}); 

}

+0

ありがとうございます!私はいくつかのエラーが発生しますが、私はそれを修正しようとします私にそれを行う主な方法を与えてくれてありがとう! :) –

+0

今すぐ使用してください。 bindView()のボタンを取得します。幸運を祈る。 – ADM

+0

私は今理解する、ありがとう! –

関連する問題