您能否帮助我在TextView
位置找到onClick
,以便我可以执行setText
之类的内容,应用动画,更改背景等。
我在MainActivity中的gridView
final GridView gv = (GridView) findViewById(R.id.gridView1);
gv.setAdapter(g);
gv.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//TODO: IN HERE I WANT TO CHANGE TEXT, APPLY ANIMATION,AND CHANGE COLOR OF TEXTVIEW PRESENT IN CUSTOM LAYOUT
// SO I WANT TO FIND THE TEXTVIEW AS WE NORMALLY DO WITH findViewById();
}
});
我的自定义布局我找到了TextView
atomicNumber的内容,以便可以应用更改文本并执行其他操作。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="50dip"
android:layout_height="50dip"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="1"
android:textSize="15dip"
android:id="@+id/atomicNumber"
android:gravity="right"
android:layout_marginTop="5dip"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="H"
android:textSize="20dip"
android:id="@+id/elementSymbol"
android:gravity="center"/>
</LinearLayout>
我试图找到解决方案但找不到一个
答案 0 :(得分:1)
您可以在onItemClickListener中获取它。你走了:
gv.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//TODO: IN HERE I WANT TO CHANGE TEXT, APPLY ANIMATION,AND CHANGE COLOR OF TEXTVIEW PRESENT IN CUSTOM LAYOUT
// SO I WANT TO FIND THE TEXTVIEW AS WE NORMALLY DO WITH findViewById();
// You can use view object to apply findviewbyId method
TextView myTextView = (TextView) view.findViewById(R.id.yourTextview);
}
});