2017-12-01 11 views
-2

나는 자신의 레이아웃을 가진 "activityCatalog"를 가지고 있으며,이 중 다른 레이아웃 마녀는 목록 항목 레이아웃입니다. 목록 항목 레이아웃에는 텍스트보기와 버튼이 있습니다. 나는 액티비티를 시도하고 "activityCatalog"에서이 버튼을 사용하여 목록 항목의 텍스트 뷰를 변경하지만 널 포인터 예외가 다시 발생합니다.다른 레이아웃의 텍스트 뷰에서 텍스트 변경

아이디어가 있으십니까? 나에게 모든 질문에

물어 어댑터 : 공용 클래스 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

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) { //... } }); 

}. 어댑터에서 해보십시오. – ADM

+0

전체 코드를 게시하고 명확하게 묻습니다. – Raja

+0

어댑터를 사용했지만 버튼에 정확히 액세스 할 수 없습니다. –

답변

0

this.You이 어댑터의 getView 수행해야처럼 당신은리스트 뷰 항목에 액세스 할 수 없습니다(). 당신은 다음과 같은리스트 뷰 항목에 액세스 할 수 없습니다

+0

감사합니다! 나는 약간의 오류가 있지만 그것을 고치려고 노력할 것입니다. 그것을 할 수있는 주된 방법을 주셔서 감사합니다! :) –

+0

지금 사용하십시오. bindView()에서 버튼을 가져옵니다. 행운을 빌어 요. – ADM

+0

나는 지금 이해한다, u를 알아라! –