私は本当にこれにこだわっています。数量を増やし、数量に基づいて価格を更新する単純な textswitcher を実行しようとしています。現在、私のxmlには、数量を増やすためだけにTextSwitcher内にTextViewのようなものがあります。でテキストビューを取得しfindViewById(R.id.quantity)
ます。
これは、増分量を設定するために見つけなければならないものです(私はViewFactoryを実装しています)
switcher = (TextSwitcher) findViewById(R.id.switcher);
switcher.setFactory(this);
quantity = (TextView) findViewById(R.id.quantity);
makeView() もオーバーライドしています
@Override
public View makeView() {
return quantity;
}
また、インクリメント ボタンを押すと、カウンターがインクリメントされ、スイッチャーのテキストが現在のカウントに設定されます。このような:
switcher.setText(String.valueOf(currentQuantity));
誰かが私が間違っていることを教えてもらえますか?? この行でヌルポインターを取得し続けます。
switcher.setFactory(this);
XML スニペットは次のとおりです。
<TextSwitcher android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/switcher">
<TextView android:text="TextView" android:id="@+id/quantity" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</TextSwitcher>