ListdataReply.java


public class ListDataReply {


    String num;

    String id;

    String text;

    String time;

    String psurl;


    public ListDataReply(String num, String id, String text, String time, String psurl) {

        this.num = num;

        this.id = id;

        this.text = text;

        this.time = time;

        this.psurl = psurl;

    }


    public String getNum() {

        return num;

    }


    public void setNum(String num) {

        this.num = num;

    }


    public String getId() {

        return id;

    }


    public void setId(String id) {

        this.id = id;

    }


    public String getText() {

        return text;

    }


    public void setText(String text) {

        this.text = text;

    }


    public String getTime() {

        return time;

    }


    public void setTime(String time) {

        this.time = time;

    }


    public String getPsurl() {

        return psurl;

    }


    public void setPsurl(String psurl) {

        this.psurl = psurl;

    }

}



ReplyListAdapter.java


package com.src.ReviewBBS;


import java.util.ArrayList;

import java.util.Collections;


import android.view.View;

import android.view.ViewGroup;


import com.widget.InfiniteScrollListAdapter;

public class ReplyListAdapter extends InfiniteScrollListAdapter {


    // A placeholder for all the data points

    private ArrayList<ListDataReply> entries = new ArrayList<ListDataReply>();

    private NewPageListener newPageListener;


    // A demo listener to pass actions from view to adapter

    public static abstract class NewPageListener {

        public abstract void onScrollNext();

        public abstract View getInfiniteScrollListView(int position, View convertView, ViewGroup parent);

    }


    public ReplyListAdapter(NewPageListener newPageListener) {

        this.newPageListener = newPageListener;

    }


    public void addEntriesToTop(ArrayList<ListDataReply> entries) {

        // Add entries in reversed order to achieve a sequence used in most of messaging/chat apps

        if (entries != null) {

            Collections.reverse(entries);

        }

        // Add entries to the top of the list

        this.entries.addAll(0, entries);

        notifyDataSetChanged();

    }


    public void addEntriesToBottom(ArrayList<ListDataReply> entries) {

        // Add entries to the bottom of the list

        this.entries.addAll(entries);

        notifyDataSetChanged();

    }


    public void clearEntries() {

        // Clear all the data points

        this.entries.clear();

        notifyDataSetChanged();

    }


    @Override

    public int getCount() {

        return entries.size();

    }


    @Override

    public Object getItem(int position) {

        return entries.get(position);

    }


    @Override

    public long getItemId(int position) {

        return position;

    }


    @Override

    public void onScrollNext() {

        if (newPageListener != null) {

            newPageListener.onScrollNext();

        }

    }


    @Override

    public View getInfiniteScrollListView(int position, View convertView, ViewGroup parent) {

        if (newPageListener != null) {

            return newPageListener.getInfiniteScrollListView(position, convertView, parent);

        }

        return convertView;

    }


}



ReviewViewReplyActivity.java


public class ReviewViewReplyActivity extends BaseActivity {


    ////////////////////////// <infinelistScrollsview> start ///////////////////////////////////////

    ArrayList<ListDataReply> moguwaiEntries;

    private ReplyListAdapter replyListAdapter;

    static DrawableManager DM = new DrawableManager();

    private static final int SEVER_SIDE_BATCH_SIZE = 10;

    private InfiniteScrollListView demoListView;

    private BogusRemoteService bogusRemoteService;

    private Handler handler;

    private AsyncTask<Void, Void, Void> fetchAsyncTask;

    ////////////////////////// <infinelistScrollsview> end ///////////////////////////////////////


.......................(중략)

}


   @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        moguwaiListScrollsview();


................(중략)

    }


   public void moguwaiListScrollsview(){



        ////////////////////////////////////////////

        handler = new Handler();


        demoListView = (InfiniteScrollListView) this.findViewById(R.id.listview_review);


        LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        demoListView.setLoadingView(layoutInflater.inflate(R.layout.loading_view_demo, null));

        replyListAdapter = new ReplyListAdapter(new ReplyListAdapter.NewPageListener() {

            @Override

            public void onScrollNext() {

                Util.log("moguwai","===========> onScrollNext()22 <==========");

                fetchAsyncTask = new AsyncTask<Void, Void, Void>() {

                    @Override

                    protected void onPreExecute() {

                        // Loading lock to allow only one instance of loading

                        replyListAdapter.lock();

                    }

                    @Override

                    protected Void doInBackground(Void ... params) {

                        Util.log("moguwai","===========> onScrollNext()11 <==========");

                        //String temp = params[0];

                        // Mimic loading data from a remote service


                        // 이부분 거창하게 클래스에 이런 함수 쓸필요없이

                        //

                        Util.log("moguwai","===========> onScrollNext()55 <==========");

                        //result = getDBtoArray(iPage);

                        Util.log("moguwai","===========> onScrollNext()66 <==========");

                        //iPage+=10;

                        //return result;

                        return null;

                    }

                    @Override // jimin

                    protected void onPostExecute(Void result2) { // 추가하는부분

                        Util.log("moguwai", "===========> onPostExecute 시작<==========");

                        Util.log("moguwai","===========>iState<===["+iState);

                        // ArrayList<ListDataReview> result;


                        switch(iState){

                            case 0:


                                getListview(0);



                                break;


                        }





                    };

                    @Override

                    protected void onCancelled() {

                        // Tell the adapter it is end of the list when task is cancelled

                        replyListAdapter.notifyEndOfList();

                    }

                }.execute();

            }

            @Override

            public View getInfiniteScrollListView(int position, View convertView, ViewGroup parent) {

                // Customize the row for list view

                if(convertView == null) {

                    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                    convertView = layoutInflater.inflate(R.layout.row_reply, null);

                }

                ListDataReply name = (ListDataReply) replyListAdapter.getItem(position);

                if (name != null) {

                    TextView rowText = (TextView) convertView.findViewById(R.id.row_text2);

                    ImageView rowPsurl = (ImageView) convertView.findViewById(R.id.row_psurl2);

                    TextView rowTime = (TextView) convertView.findViewById(R.id.row_time2);

                    TextView rowId = (TextView) convertView.findViewById(R.id.row_id2);


                    //row_id row_catalog

                    //row_time



                    // 실제 Card에 Display하는 부분

                    rowId.setText(name.getId());

                    rowText.setText(name.getText());

                    DM.fetchDrawableOnThread(name.getPsurl(), rowPsurl);  //비동기 이미지 로더

                    rowTime.setText(name.getTime());





                }

                return convertView;

            }

        });

        demoListView.setAdapter(replyListAdapter);

        // Display a toast when a list item is clicked

        demoListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {


            public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {


                boolean post = handler.post(new Runnable() {

                    @Override

                    public void run() {

                        ListDataReply name = (ListDataReply) replyListAdapter.getItem(position);

                        // Toast.makeText(YouTubeActivity.this, name.getTitle() + " " + getString(R.string.ordered), Toast.LENGTH_SHORT).show();



                        String strGetID = name.getId();

                        String strGetTitle = name.getText();

                        String strUrl = name.getPsurl();

                        String strNum = name.getNum();

                        // 새로 추가

                        String strPsurl = name.getPsurl();

                        String strTime = name.getTime();


                        String strText = name.getText();

                        // hXBBH3aN0LA

                        Log.d("moguwai", "strGetID = " + strGetID);

                        Log.d("moguwai", "strGetTitle = " + strGetTitle);

                        Log.d("moguwai", "strNum= " + strNum);

                        Log.d("moguwai", "strPsurl= " + strPsurl);

                        Log.d("moguwai", "strTime= " + strTime);


                        Log.d("moguwai", "strText= " + strText);



                    }

                });

            }

        });

    }

    public void getListview(int iNum){

        String strUrl="";

        ArrayList<ListDataReply> result;

        switch(iNum)

        {

            case 0: // 전체

                strUrl="http://121.182.120.85/getreviewlist1.php?page=";

                break;


        }



        result = getDBtoArray(iPage,strUrl);

        iPage += 10;

        if (result == null || result.isEmpty()) {

            replyListAdapter.notifyEndOfList();


        } else {


            // List

            replyListAdapter.addEntriesToBottom(result);


            // Add or remove the loading view depend on if there might be more to load

            if (result.size() < SEVER_SIDE_BATCH_SIZE) {

                replyListAdapter.notifyEndOfList();

            } else {

                replyListAdapter.notifyHasMore();

            }

            // Get the focus to the specified position when loading completes

        } // else


        Util.log("moguwai", "===========> onPostExecute 끝<==========");

    }

    public ArrayList<ListDataReply> getDBtoArray(int page,String strUrl){

        ArrayList<ListDataReply> tempEntries = new ArrayList<ListDataReply>();



        String strRet="";

        strRet = requestDataForServer(1, strUrl+page, this);


        String num="";

        String psurl="";

        String id="";

        String time="";

        String text="";

        JSONArray ja = null;

        try {

            Util.log("moguwai","===========> Debug1");

            ja = new JSONArray(strRet);

            Util.log("moguwai","===========> Debug2");

        } catch (JSONException e) {

            e.printStackTrace();

            Util.log("moguwai", "===========> Debug3");

        }

        Log.d("moguwai", "ja.length()="+ja.length());

        for(int i=0;i<ja.length();i++)

        {

            JSONObject obj = null;

            try {

                obj = ja.getJSONObject(i);

                num = obj.getString("num");

                psurl = obj.getString("psurl");

                Log.d("moguwai", "psurl: "+i+"번째 :"+psurl);

                id = obj.getString("id");

                time = obj.getString("time");

                text = obj.getString("text");



            } catch (JSONException e) {

                e.printStackTrace();

            }


            ListDataReply tempList1 =  new ListDataReply(num,id,text,time,psurl);

            tempEntries.add(tempList1);

        }


        return tempEntries;

    }


 public void getListFromDB(int State){

        iState =State;

        replyListAdapter.onScrollNext();

    }

    public void resetListview(){

        ///// 전에꺼 지우는 코드

        iPage=0;

        replyListAdapter.clearEntries();

        replyListAdapter.notifyEndOfList();

        ////////////////////////////

    }


    @Override

    protected void onResume() {

        super.onResume();

        Log.d("moguwai", "onResume()");

        resetListview();

        getListFromDB(0);

        //reviewListAdapter.onScrollNext();

    }


row.reply.xml


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:paddingTop="5dp"

    android:paddingBottom="5dp"

    android:paddingLeft="10dp"

    android:paddingRight="5dp"

    android:layout_height="100dip"

    android:background="#ffffff"

    android:orientation="horizontal" >


    <LinearLayout

        android:layout_width="0dip"

        android:layout_height="100dip"

        android:layout_weight="1.5"

        android:orientation="horizontal" >


        <ImageView

            android:id="@+id/row_psurl2"

            android:layout_width="match_parent"

            android:layout_height="match_parent" >

        </ImageView>

    </LinearLayout>


    <LinearLayout

        android:layout_width="0dip"

        android:layout_height="100dip"

        android:layout_weight="4"

        android:weightSum="1"

        android:orientation="vertical" >


        <LinearLayout

            android:layout_width="match_parent"

            android:layout_weight="0.35"

            android:layout_height="0dip"

            android:weightSum="1"

            android:orientation="horizontal" >


            <LinearLayout

                android:layout_width="0dip"

                android:layout_weight="0.25"

                android:layout_height="match_parent"

                android:orientation="horizontal" >

                <TextView

                    android:id="@+id/row_id2"

                    android:textColor="#000000"

                    android:layout_width="match_parent"

                    android:layout_height="match_parent"

                    android:text="아이디"

                    android:textSize="11dp"

                    android:singleLine="true"

                    >

                </TextView>




            </LinearLayout>



            <LinearLayout

                android:layout_width="0dip"

                android:layout_weight="0.75"

                android:layout_height="match_parent"

                android:orientation="horizontal" >

                <TextView

                    android:id="@+id/row_time2"

                    android:textColor="#000000"

                    android:layout_width="match_parent"

                    android:layout_height="match_parent"

                    android:text="시간"

                    android:textSize="11dp"

                    android:singleLine="true"

                    >

                </TextView>




            </LinearLayout>


        </LinearLayout>

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_weight="0.65"

            android:layout_height="0dip"

            android:orientation="horizontal" >

            <TextView

                android:id="@+id/row_text2"

                android:textColor="#000000"

                android:layout_width="match_parent"

                android:layout_height="match_parent"

                android:text="본문"

                >

            </TextView>



        </LinearLayout>



    </LinearLayout>


</LinearLayout>



[Github 필요한 파일 추출]

modifybymoguwai.zip



Posted by 모과이IT
,