這是我的XML代碼,我已經2個按鈕向上和向下箭頭,我想以顯示如下內容時,向下箭頭被點擊了,否則我想如何使文本可見,匆匆上按鈕單擊事件
lin1.setVisibility(View.VISIBLE);
在我的代碼bt它不工作..可以有人幫我這個...?
在此先感謝
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Hrmbg"
tools:context="com.agna.hrm_sainmarks.PersonalDetails" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:id="@+id/lin1"
android:background="@color/Hrmbg"
android:weightSum="2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="right"
android:text="@string/tpersonal"
android:textSize="18dp" />
<ImageButton
android:id="@+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:background="@null"
android:src="@drawable/uparrow"
android:visibility="visible" />
<ImageButton
android:id="@+id/down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:background="@null"
android:src="@drawable/downarrow" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/marital"
android:textSize="18dp" />
<TextView
android:id="@+id/marital"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="Married"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View01"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/spouse"
android:textSize="18dp" />
<TextView
android:id="@+id/spouse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="Shalini"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View02"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/spouseprofession"
android:textSize="18dp" />
<TextView
android:id="@+id/spouseprofession"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="House Wife"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View03"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/children"
android:textSize="18dp" />
<TextView
android:id="@+id/children"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="Two"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View04"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/fathername"
android:textSize="18dp" />
<TextView
android:id="@+id/fathername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="Aravind"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View05"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/fatherprofession"
android:textSize="18dp" />
<TextView
android:id="@+id/fatherprofession"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="Business"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View06"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/fatherage"
android:textSize="18dp" />
<TextView
android:id="@+id/fatherage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="61"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View07"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/mothername"
android:textSize="18dp" />
<TextView
android:id="@+id/mothername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="Meenakshi"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View08"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/motherprofession"
android:textSize="18dp" />
<TextView
android:id="@+id/motherprofession"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="House Wife"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View09"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/motherage"
android:textSize="18dp" />
<TextView
android:id="@+id/motherage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="59"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View10"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:background="@color/Hrmbg"
android:weightSum="2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="right"
android:text="@string/sibling"
android:textSize="18dp" />
<ImageButton
android:id="@+id/othrdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:background="@null"
android:src="@drawable/uparrow"
android:visibility="visible" />
<ImageButton
android:id="@+id/othrup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:background="@null"
android:src="@drawable/downarrow" />
</LinearLayout>
<View
android:id="@+id/View11"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/name"
android:textSize="18dp" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="Ravi Varma"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View12"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/age"
android:textSize="18dp" />
<TextView
android:id="@+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="25"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View13"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/profession"
android:textSize="18dp" />
<TextView
android:id="@+id/profession"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="Professor"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
<View
android:id="@+id/View14"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/company"
android:textSize="18dp" />
<TextView
android:id="@+id/company"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="10dp"
android:text="PSG CAS"
android:textSize="18dp"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
PersonalDetails.java
public class PersonalDetails extends Activity implements OnClickListener {
ImageButton up,down;
LinearLayout lin1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_personal_details);
up = (ImageButton)findViewById(R.id.up);
down = (ImageButton)findViewById(R.id.down);
lin1=(LinearLayout)findViewById(R.id.lin1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.personal_details, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.equals(up))
{
lin1.setVisibility(View.VISIBLE);
}
if(v.equals(down))
{
down.setVisibility(View.INVISIBLE);
}
}
}
哪裏是你的MainActivity.java代碼? –
讓點擊偵聽器在您點擊箭頭後觸發?什麼是lin1? – panda