2

I'm trying to show a list with the list items from my database having 2 parameters, but the list didn't show.

Here's my query database from php:

$query = mysql_query("SELECT d.model_name from detail_product d join brand b on d.id_brandtype = b.id_brand join biketype t on d.id_biketype = t.id_type  where d.id_brandtype = 1 and d.id_biketype=1");

I've set the parameter there.

and here's my DAO:

public class info_xc_dao {

public final static int VIEW_POL_XC = 0;

private static final String URL_VIEW_POL_XC = ServerConfiguration.SERVER_URL
        + "polygon_xc.php";

private int Action;
pol_xc_Result pol_xc_Result;

public info_xc_dao(pol_xc_Result pol_xc_Result) {
    // TODO Auto-generated constructor stub
    this.pol_xc_Result = pol_xc_Result;
}

public void view_pol_xc() {
    Action = VIEW_POL_XC;
    new ConnectionHandler(connectionResult, null, URL_VIEW_POL_XC,
            ConnectionHandler.GET);
}

public ConnectionResult connectionResult = new ConnectionResult() {

    @Override
    public void gotResult(String result, String message) {
        // TODO Auto-generated method stub
        if (result != null) {
            switch (Action) {
            case VIEW_POL_XC:
                try {
                    JSONObject jsonObject = null;
                    jsonObject = new JSONObject(result);
                    int response = jsonObject.getInt("result");
                    if (response != 0) {
                        JSONArray jsonArray = new JSONArray(
                                jsonObject.getString("data"));

                        ArrayList<Entity_Detail_Product> arrayList = new ArrayList<Entity_Detail_Product>();
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject pol_xc = new JSONObject(jsonArray
                                    .get(i).toString());

                            Entity_Detail_Product ent_detail_product = new Entity_Detail_Product();
                            ent_detail_product.setModel_name(pol_xc
                                    .getString("model_name"));
                            arrayList.add(ent_detail_product);
                        }
                        pol_xc_Result.gotResult(arrayList, null, Action);
                        
                    } else {
                        String error_message = jsonObject
                                .getString("message");
                        pol_xc_Result.gotResult(null, error_message,
                                Action);
                    }
                } catch (JSONException e) {
                    // TODO: handle exception
                    pol_xc_Result.gotResult(null,
                            "Failed parsing data from database. Please try again.. "
                                    + e.getMessage(), Action);
                    Log.e("CON ERROR", e.getMessage());
                }
            }
        } else {
            pol_xc_Result.gotResult(null, message, Action);
            Log.e("CON ERROR", message);
        }
    }
};

public static abstract class pol_xc_Result {
    public abstract void gotResult(Object obj, String message, int action);
}

and here's my activity to call DAO.

public class Information_XC_Activity extends ListActivity {
WebView mWebView;
TextView tv;
private Adapter_DetailPolXC adapterDetailPolXC;

private ListView mainListView;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.info_xc);

    final ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
    actionBar.setTitle(getString(R.string.app_name));

    int index = getIntent().getIntExtra("text", 0);

    mWebView = (WebView) findViewById(R.id.webview_xc);

    String temp = "<html><body>" + "<p align=\"justify\">"
            + getString(R.string.xc_info + index) + "</p> "
            + "</body></html>";
    mWebView.loadData(temp, "text/html", "utf-8");

    ArrayList<Entity_Detail_Product> arraylist = new ArrayList<Entity_Detail_Product>();

    adapterDetailPolXC = new Adapter_DetailPolXC(this, R.layout.info_row,
            arraylist);
     setListAdapter(adapterDetailPolXC);
    
    new info_xc_dao(response).view_pol_xc();
}

pol_xc_Result response = new pol_xc_Result() {
    @Override
    public void gotResult(Object obj, String message, int action) {
        // TODO Auto-generated method stub
        // actionBar.setProgressBarVisibility(View.INVISIBLE);

        @SuppressWarnings("unchecked")
        ArrayList<Entity_Detail_Product> arrayList = (ArrayList<Entity_Detail_Product>) obj;
        AlertDialog.Builder builder = new AlertDialog.Builder(
                Information_XC_Activity.this);

        if (arrayList == null) {
            builder.setIcon(R.drawable.alert_warning);
            builder.setTitle("Error");
            builder.setMessage("Data Not Found !");
            builder.setNegativeButton("Ok",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();

        } else {
            for (Entity_Detail_Product entity_Detail_Product : arrayList) {
                adapterDetailPolXC.add(entity_Detail_Product);
            }
            adapterDetailPolXC.notifyDataSetChanged();
        }

    }

};

private class Adapter_DetailPolXC extends
        ArrayAdapter<Entity_Detail_Product> {
    private ArrayList<Entity_Detail_Product> items;

    public Adapter_DetailPolXC(Context context, int textViewResourceId,
            ArrayList<Entity_Detail_Product> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View v = convertView;
        if (v == null) {
            LayoutInflater layoutInflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = (View) layoutInflater.inflate(R.layout.info_xc, null);
        }
        Entity_Detail_Product adapter_Detail_Product = items.get(position);
        if (adapter_Detail_Product != null) {
            TextView textView = (TextView) v.findViewById(R.id.tv_test);
            if (textView != null)
                textView.setText(adapter_Detail_Product.getModel_name());
        }
        return v;
    }

}

and here's my logcat :

09-22 12:41:30.239: W/IInputConnectionWrapper(12808): showStatusIcon on inactive InputConnection
09-22 12:41:33.129: E/HttpResponse(12808): {"result":1,"data":[{"0":"1","id_brand":"1","1":"Polygon","brand_name":"Polygon"},{"0":"2","id_brand":"2","1":"United Bike","brand_name":"United Bike"},{"0":"3","id_brand":"3","1":"WimCycle","brand_name":"WimCycle"}]}
09-22 12:41:35.009: E/HttpResponse(12808): {"result":1,"data":[{"0":"1","id_type":"1","1":"Cross Country (XC)","type_name":"Cross Country (XC)"},{"0":"2","id_type":"2","1":"Bicycle Motocross (BMX)","type_name":"Bicycle Motocross (BMX)"},{"0":"3","id_type":"3","1":"Free Ride (FR)","type_name":"Free Ride (FR)"},{"0":"4","id_type":"4","1":"DownHill (DH)","type_name":"DownHill (DH)"},{"0":"5","id_type":"5","1":"DirtJump (DJ)","type_name":"DirtJump (DJ)"},{"0":"6","id_type":"6","1":"Road Bike (RB)","type_name":"Road Bike (RB)"}]}
09-22 12:41:37.219: D/PhoneWindow(12808): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@405440f0 has no id.
09-22 12:41:37.519: I/webclipboard(12808): clipservice: android.sec.clipboard.ClipboardExManager@405d4d40
09-22 12:41:37.839: V/webview(12808): OnSizeChanged: Enter 
09-22 12:41:37.859: E/HttpResponse(12808): {"result":1,"data":[{"0":"1","id_type":"1","1":"Cross Country (XC)","type_name":"Cross Country (XC)"},{"0":"2","id_type":"2","1":"Bicycle Motocross (BMX)","type_name":"Bicycle Motocross (BMX)"},{"0":"3","id_type":"3","1":"Free Ride (FR)","type_name":"Free Ride (FR)"},{"0":"4","id_type":"4","1":"DownHill (DH)","type_name":"DownHill (DH)"},{"0":"5","id_type":"5","1":"DirtJump (DJ)","type_name":"DirtJump (DJ)"},{"0":"6","id_type":"6","1":"Road Bike (RB)","type_name":"Road Bike (RB)"}]}
09-22 12:41:38.169: E/CON ERROR(12808): No value for model_name
09-22 12:41:38.859: V/webview(12808): ZoomScale 3 mPreserveZoom: false
09-22 12:41:38.889: D/CONTEXT(12808): m_mainFrame->editor()->hasComposition not 
09-22 12:41:38.959: D/CONTEXT(12808): m_mainFrame->editor()->hasComposition not 

enter image description here

4

0 回答 0