package mars.Travel;
 
import java.util.ArrayList;
import java.util.List;
 
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
 
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import aroa.fun.Json;
import aroa.fun.PlayData;
 
public class ListMoreTest extends Activity {
        ListView lv;
        Button btnLeft, btnRight;
         
        View.OnClickListener cl;
         
        MoreAdapter ma;
         
         
        int VIEW_COUNT = 5;
         
        int index = 0;
        List<PlayData> list = new ArrayList<PlayData>();
 
        Json ss =new Json();
        String n=ss.fanhui("information","v_spots","http://219.229.167.61/admin/request.php?qq=498002079");
 
         
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.play);
         
        initView();
        try{
                JSONArray jArray=new JSONArray(n);
                for(int i=0;i<jArray.length();i++){
                        JSONObject json_data=jArray.getJSONObject(i);
                        PlayData sp = new PlayData();
                        sp.setScenicSpots_name(json_data.getString("ScenicSpots_name"));
                        sp.setS_price("票价:"+json_data.getString("S_price")+"元");
                         sp.setS_introduction("景点介绍:"+json_data.getString("S_introduction"));
                         sp.setS_id(json_data.getInt("S_id"));
                         list.add(sp);
                }
                 }catch(JSONException e){
                    Log.e("log_tag","错误" + e.toString());
            }
         
        ma = new MoreAdapter(this,this,list);
        lv.setAdapter(ma);
         
         
        cl = new Button.OnClickListener(){
                        @Override
                        public void onClick(View v) {
                                // TODO Auto-generated method stub
                                switch(v.getId()){
                                case R.id.btnLeft:
                                        leftView();
                                        break;
                                         
                                case R.id.btnRight:
                                        rightView();
                                        break;
                                }
                        }
 
        };
         
        btnLeft.setOnClickListener(cl);
        btnRight.setOnClickListener(cl);
         
        checkButton();
         
    }
     
    public void initView(){
            lv = (ListView)findViewById(R.id.Sport_listView);
             
            btnLeft = (Button)findViewById(R.id.btnLeft);
            btnRight = (Button)findViewById(R.id.btnRight);
             
    }
     
    public void leftView(){
            index--;
             
            ma.notifyDataSetChanged();
             
            checkButton();
    }
     
    public void rightView(){
            index++;
             
            ma.notifyDataSetChanged();
             
            checkButton();
    }
     
    public void checkButton(){
            if(index <=0){
                    btnLeft.setEnabled(false);
            }
            else if(list.size() - index*VIEW_COUNT <= VIEW_COUNT){
                    btnRight.setEnabled(false);
            }
            else {
                    btnLeft.setEnabled(true);
                    btnRight.setEnabled(true);
            }
             
    }
     
    public class MoreAdapter extends BaseAdapter {
            Activity activity;
                private LayoutInflater layoutInflater;
                private List<PlayData> list;
                public List<TextView> txtList;
 
            public MoreAdapter(Activity a,Context context, List<PlayData> list2) {
                    this.layoutInflater = LayoutInflater.from(context);
                    this.list = list2;
                    activity = a;
            }
             
                @Override
                public int getCount() {
                        // TODO Auto-generated method stub
                        //return data.length;
                         
                        int ori = VIEW_COUNT * index;
                         
                        if(list.size() - ori < VIEW_COUNT ){
                                return list.size() - ori;
                        }
                        else {
                                return VIEW_COUNT;
                        }
                         
                }
 
                @Override
                public Object getItem(int position) {
                        // TODO Auto-generated method stub
                        return position;
                }
 
                @Override
                public long getItemId(int position) {
                        // TODO Auto-generated method stub
                        return position;
                }
 
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                        if(convertView == null){
                                convertView = layoutInflater.inflate(R.layout.listview, null);
                        }
                        PlayData pd=(PlayData )getItem(position);
                        txtList = new ArrayList<TextView>();
                        TextView ScenicSpots_name = (TextView) convertView.findViewById(R.id.ScenicSpots_name);
                        TextView S_price =(TextView) convertView.findViewById(R.id.S_price);
                        TextView S_introduction =(TextView) convertView.findViewById(R.id.S_introduction);
                        ScenicSpots_name.setText(pd.getScenicSpots_name());
                        S_price.setText(pd.getS_price());
                        S_introduction.setText(pd.getS_introduction());
                         
                        //Activity中要获取数量的list
                        txtList.add(ScenicSpots_name);
                        txtList.add(S_price);
                        txtList.add(S_introduction);
                 
                        return convertView;
                }
             
    }
}
是拿我自己的代码和别人提供的代码相结合的 但是不知道哪里结合出错了一直fc