2011-11-08 7 views
0

私が作成したWebサービスから返される名前のリストを表示する簡単なAndroidリストビューコードがあります。提出)のエントリをチェック/マーク2つの各ボタンを押すことでデータベースにデータを格納するためのボタンをAndroidリストビューに表示

1)自分のデータベース

2の別の列に格納する必要があります:私はので、リストの最後に三つのボタンを追加する必要がありますボタンを押してデータを送信する

データを保存するには、ユーザーが送信ボタンをクリックしたときにWebサービスを呼び出す予定です。

私の問題は、両方のボタンのチェック値をどのように保存するのですか?そのデータをWebサービス経由で送信するにはどうすればよいですか?私は以下のコードを実行すると

はまた、私は誰もが任意のアイデアを提案してくださいすることができ、ボタン

を見ることができないのですか?

私のAndroidのコード:

 package com.example; 

     import java.net.SocketException; 
     import android.app.Activity; 
     import android.os.Bundle; 
     import android.view.View; 
     import android.widget.ArrayAdapter; 
     import android.widget.Button; 
     import android.widget.ListView; 
     import android.widget.TextView; 
     import org.ksoap2.SoapEnvelope; 
     import org.ksoap2.serialization.SoapObject; 
     import org.ksoap2.serialization.SoapPrimitive; 
     import org.ksoap2.serialization.SoapSerializationEnvelope; 
     import org.ksoap2.transport.HttpTransportSE; 


public class display extends Activity { 

private static final String SOAP_ACTION = "http://tempuri.org/getData"; 

    private static final String METHOD_NAME = "getData"; 

    private static final String NAMESPACE = "http://tempuri.org/"; 
    private static final String URL = "http://10.0.2.2/getdata2/Service1.asmx"; 
TextView tv; 

private ListView lView; 
private Button markpresent; 
private Button markabsent; 
    private Button submit; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.displaydata); 
    tv=(TextView)findViewById(R.id.text1); 

      String[] arr2= call(); 
     lView = (ListView) findViewById(R.id.ListView01); 
     //Set option as Multiple Choice. So that user can able to select more the one option from list 
     lView.setAdapter(new ArrayAdapter<String>(this, 
     android.R.layout.simple_list_item_multiple_choice, arr2)); 
     lView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 

     markpresent = (Button) findViewById(R.id.Button01); 
     markpresent.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
     //put checked entries in database 
     } 
     }); 

     markabsent = (Button) findViewById(R.id.Button02); 
     markabsent.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      //put checked entries in database 
     } 
     }); 

     submit = (Button) findViewById(R.id.Button03); 
     submit.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      //call another web service for insertion of data 
     } 
     }); 

} 

//webservice call works fine 

    public String[] call() 
    { 

    SoapPrimitive responsesData = null; 

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( 
    SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

    androidHttpTransport.debug = true; 

    try { 

    androidHttpTransport.call(SOAP_ACTION, envelope); 

    responsesData = (SoapPrimitive) envelope.getResponse(); 
    System.out.println(" --- response ---- " + responsesData); 

    } catch (SocketException ex) { 
    ex.printStackTrace(); 
    } catch (Exception e) { 
    e.printStackTrace(); 
    } 
    System.out.println(" ----" + responsesData); 

    String serviceResponse= responsesData .toString(); 


    String[] temp; 
    String delimiter = "#"; 
    temp= serviceResponse.split(delimiter); 
    System.out.println(" ---- length ---- " + temp.length); 

    return temp; 


       } 
      } 

マイdisplaydata.xmlファイル

 <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <ListView android:id="@+id/ListView01" android:layout_height="wrap_content" 
    android:layout_width="fill_parent"></ListView> 
    <Button 
    android:layout_height="wrap_content" 
    android:id="@+id/Button01" android:text="Mark present" 
    android:layout_width="fill_parent" 
    /> 
    <Button 
    android:layout_height="wrap_content" 
    android:id="@+id/Button02" android:text="Mark absent" 
     android:layout_width="fill_parent" 
    /> 

+0

xmlファイルを投稿すると、ボタンが表示されない理由がわかります。 – Craigy

+0

@Craigy:はいそれを追加しました –

答えて

1

あなたのボタンが表示されない理由は、あなたのXMLが間違っているということです。あなたがしたい場合は、最後に

markpresent = (Button) findViewById(R.id.Button01); 
    markpresent.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      SparseBooleanArray checked = lView.getCheckedItemPositions(); 

      ArrayList<String> items = new ArrayList<String>(); 
      for (int i = 0; i < arr2.length; i++) { 
       if (checked.get(i)) { 
        items.add(arr2[i]); 
       } 
      } 

      Log.d("", "items:"); 
      for (String string : items) { 
       Log.d("", string); 
      } 

      // put checked entries in database 
     } 
    }); 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ListView 
     android:id="@+id/ListView01" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 
    </ListView> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/Button01" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Mark present" /> 

     <Button 
      android:id="@+id/Button02" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Mark absent" /> 
    </LinearLayout> 
</RelativeLayout> 

あなたがボタンを押すと、リストビューからチェックされた項目を取得したい場合は、このような何かを:私は、これはあなたがしたいレイアウトを実現すると信じてデータベースにデータを格納する方法を学ぶためにここに

見ますあなたのWebサービスにデータを送信する場合は

とは、それが本当にサーバーが予想されているプロトコルに依存しますが、あなたは最初からそれを設計している場合は、ここでいくつかのオプションがあります

+0

thnxたくさん!! :-) –