0

これは私のgridview.javaクラスです

public class TextGridActivity extends Activity {

String[] _cataId=new String[100] ;
String[] _cataName=new String[100];
  String[] _cataDes=new String[100];
  String[] _cataCode=new String[100];
      int num,k=0;
         int len=10;
      String[] temp ;
DataAdapter mAdapter;

GridView gridView;
private static String SOAP_ACTION = "http://tempuri.org/GetItemCategory";

 private static String NAMESPACE = "http://tempuri.org/";

     String METHOD_NAME = "GetItemCategory";



 String res="";
  private static String URL = "http://10.0.2.2:63395/Service1.asmx";

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

fillTitle();

    createViews();
}

    public void createViews()
      { 

         mAdapter = new DataAdapter(this,_cataId,_cataName,_cataDes,_cataCode,len);
      GridView gridview = (GridView) findViewById(R.id.gridview);  

    gridview.setAdapter(mAdapter);}
//method for soap call
       public void fillTitle(){
       SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    try {

     androidHttpTransport.call(SOAP_ACTION, envelope);
     KvmSerializable response = (KvmSerializable)envelope.bodyIn;

    res= response.getProperty(0).toString();
    Toast.makeText(this, res,Toast.LENGTH_LONG).show();

    String delimiter = ";";
      temp= res.split(delimiter);


    for(int i=0;i<len; i++)
    {
        _cataId[i]=temp[i].substring(29);
    //Toast.makeText(this, _cataId[i],Toast.LENGTH_LONG).show();

        _cataName[i]=temp[i+1].substring(9);
        //Toast.makeText(this, _cataName[i],Toast.LENGTH_LONG).show();

        _cataDes[i]=temp[i+2].substring(9);
        //Toast.makeText(this, _cataDes[i],Toast.LENGTH_LONG).show();

        _cataCode[i]=temp[i+3].substring(10);
        //Toast.makeText(this, _cataCode[i],Toast.LENGTH_LONG).show();

     i=i+4;



    }


} 
    catch (Exception e) {

    Toast.makeText(this, e.toString(),
    Toast.LENGTH_LONG).show();
    } }
    }

これは私のDataAdapter.javaクラスです

public class DataAdapter extends BaseAdapter
{                  
       Context mContext;

      private String[] _cataId ;
     private  String[] _cataName;
      private String[] _cataDes;
      private String[] _cataCode;
       int len;

     public DataAdapter(Context mContext, String [] cataId, String [] cataName, String[] cataDes, String[] cataCode,int len) {

         super();
          this.mContext=mContext;
         this._cataId=cataId;
         this._cataName = cataName;
         this._cataDes = cataDes;
         this._cataCode = cataCode;
           this.len = len;
         }

       private LayoutInflater mInflater;
       public DataAdapter(Context c)
       {
              mContext=c;
              mInflater = LayoutInflater.from(c);
       }
       public int getCount()
       {
              return len;
       }


       public Object getItem(int position)
       {


           return  position;

       }


    public long getItemId(int position)
       {
              return position;
       }


       public View getView(int position, View convertView, ViewGroup parent)
       {
              ViewHolder holder=null;
              if(convertView==null)
              {
                     convertView = mInflater.inflate(R.layout.customgrid, null);
                     holder = new ViewHolder();
                     holder.txtId=(TextView)convertView.findViewById(R.id.txtId);
                    // holder.txtId.setPadding(30, 10,10 , 10);
                     holder.txtName=(TextView)convertView.findViewById(R.id.txtName);
                    //holder.txtName.setPadding(30, 10, 10, 10);
                     holder.txtDes=(TextView)convertView.findViewById(R.id.txtDes);
                   // holder.txtDes.setPadding(30, 10, 10, 10);
                     holder.txtCode=(TextView)convertView.findViewById(R.id.txtCode);
                   // holder.txtCode.setPadding(30, 10, 10, 10);
                     if(position==0)
                     {                             
                           convertView.setTag(holder);
                     }
              }
              else
              {
                     holder = (ViewHolder) convertView.getTag();
              }
              holder.txtId.setText(_cataId[position]);
              holder.txtName.setText(_cataName[position]);
              holder.txtDes.setText(_cataDes[position]);
              holder.txtCode.setText(_cataCode[position]);

              return convertView;
       }
       static class ViewHolder
       {        

            TextView txtId;        
              TextView txtName; 
              TextView txtDes;
            TextView txtCode;
       }
}

データはres変数に送られ、(;)で区切られます。私はすべてのデータとそのデータをトーストして、_cataId、_cataName、_cataDes、_cataCodeに入れ、データが来るかどうかを確認するためにトーストしました。

今、私の問題は、CreateViews()メソッドを強制的に閉じることです。nグリッドで使用されるマダプターが固定されています。plzは、このメソッドを呼び出しているときに何が間違っているのか教えてください

4

1 に答える 1

0

通信は UI スレッドで行われるため、ANRが発生します。Android 4以降。

すべての長時間 (または不明な時間) 操作については、UI スレッドではないスレッドで使用し、必要な場合にのみ UI スレッドを更新します。

詳細については、これをお読みください:

http://developer.android.com/resources/articles/painless-threading.html

それを避けるために、strict モードを使用できます。

http://developer.android.com/reference/android/os/StrictMode.html

于 2012-06-12T22:53:50.150 に答える