2012-10-29 5 views
-1

ListView는 LinearLayout 유형의 여러 요소로 구성되어 있습니다. 연락처에 슬라이드 효과를 적용하는 방법 (오른쪽에 연락처 슬라이드가있을 경우 전화가 걸리고, 다른 경우에는 메시지가 쓰여집니다).위젯을 오른쪽 또는 왼쪽으로 슬라이드

+0

가 자신의 재판을 한 messages.xml? 나는 당신이 아직 시도한 것을 의미합니까? –

+0

제스처를 사용하여 슬라이드를 왼쪽 또는 오른쪽으로 찾을 수 있습니까? – suresh

답변

0

와 함께보기 호출기를 사용할 수 있습니다. 자바 파일

public class ViewPageExample extends Activity { 

private ViewPager mViewPager; 
private Context mContext; 
private MyPageAdatper mAdapter; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
mContext = this; 

mAdapter = new MyPageAdatper(); 
mViewPager = (ViewPager) findViewById(R.id.mViewPager); 
mViewPager.setAdapter(mAdapter); 
} 

private class MyPageAdatper extends PagerAdapter{ 


     @Override 
     public int getCount() { 
       //Since only contacts messages and call logs were mentioned by you 
       return 3; 
     } 


     @Override 
     public Object instantiateItem(View collection, int position) { 
      LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View mView = null ; 
      switch(position){ 
       case 0: 
        mView = inflater.inflate(R.layout.contacts, null); 
        Button btn1 = (Button) mView.findViewById(R.id.button1); 
        btn1.setOnClickListener(new OnClickListener() { 

         @Override 
         public void onClick(View v) { 
          Toast.makeText(getApplicationContext(), "Clicked", Toast.LENGTH_SHORT).show(); 
         } 
        }); 
       break; 

       case 1: 
        mView = inflater.inflate(R.layout.messages, null); 
       break; 

       case 2: 
        mView = inflater.inflate(R.layout.callogs, null); 
       break; 
      } 




       ((ViewPager) collection).addView(mView,0); 

       return mView; 
     } 


     @Override 
     public void destroyItem(View collection, int position, Object view) { 
       ((ViewPager) collection).removeView((View) view); 
     } 



     @Override 
     public boolean isViewFromObject(View view, Object object) { 
       return view==((View)object); 
     } 


     @Override 
     public void finishUpdate(View arg0) {} 


     @Override 
     public void restoreState(Parcelable arg0, ClassLoader arg1) {} 

     @Override 
     public Parcelable saveState() { 
       return null; 
     } 

     @Override 
     public void startUpdate(View arg0) {} 

} 


} 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#a4c639"> 
<android.support.v4.view.ViewPager 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@+id/mViewPager"/> 
</LinearLayout> 

callogs.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 


<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Call Logs" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 
</LinearLayout> 

contacts.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 



<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Contacts" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 

</LinearLayout> 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 



<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="SomeMessages" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

</LinearLayout> 
+0

작업을위한 탁신. 나는 내 프로그램에 당신의 코드를 적용하려고 노력했다. 먼저 ViewPager- http://goo.gl/AFXjZ의 정의로 리소스 파일을 만들었습니다. 그런 다음 MyPageAdapter.java 파일 (http://goo.gl/VsET)을 만들었습니다. 그런 다음 MainActivity.java에서 MainActivity 파일 (http://goo.gl/Ha17M)에 ListView가 정의 된 ArrayAdapter (파일 - http://goo.gl/HKtGz)를 설정했습니다. ArrayAdapter.getView에 대한 호출에서 load_content 메소드의 코드가 event_itemlayout을 비정상적으로 확장했다. 오류 : android.content.res.Resources $ NotFoundException : 리소스 ID # 0x7f070004 유형 # 0x12이 유효하지 않습니다. – psct

+0

코드를 이해할 수 없거나 일부 코드가 완료되지 않았습니다. 프로젝트 파일을 공유하십시오 (가능하면 모두 가능). –

+0

더 이상 관련없는이 작품. 감사) – psct

관련 문제