这是我的xml文件,名为create_event.xml
<LinearLayout
style="@style/create_event_exc_margin_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
style="@style/create_event_exc_infotext_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/event_title" />
<EditText
android:id="@+id/event_title"
style="@style/create_event_infotext_normal"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/extra_desc"
android:ems="10"
android:inputType="text" />
</LinearLayout>
<LinearLayout
style="@style/create_event_exc_margin_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="60dip"
android:layout_height="60dip"
android:src="@drawable/no_image"/>
<Button
android:id="@+id/upload_button"
style="@style/global_button_edit"
android:layout_width="112dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:minHeight="30dip"
android:text="@string/upload_image" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/edit_form1"
android:layout_marginTop="32dp"
android:orientation="horizontal" >
<Button
android:id="@+id/button_save"
style="@style/loginbutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="30dp"
android:text="@string/save" />
</LinearLayout>
这是我的名为Create_Event.java的java文件。在这里,你可以看到我的java文件扩展了片段。它打开了我手机的图库。但它没有选择并上传任何图像。
public class Create_Event extends SherlockFragment
{
JSONObject json;
private String event_title;
EditText Event_title;
ImageView event_logo;
Button upload;
String selectedPath1 = "NONE";
private static final int SELECT_FILE1 = 1;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
if (loading != null)
{
if(loading.isShowing())
{
loading.dismiss();
}
}
super.onCreate(savedInstanceState);
View rootView = inflater.inflate(R.layout.create_event, container, false);
Event_title=(EditText)rootView.findViewById(R.id.event_title);
event_logo=(ImageView)rootView.findViewById(R.id.imageView1);
upload=(Button)rootView.findViewById(R.id.upload_button);
upload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View args0) {
// TODO Auto-generated method stub
openGallery(SELECT_FILE1);
}
});
return rootView;
}
public void openGallery(int req_code) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Select file to upload "),
req_code);
}
在此处,单击上传按钮时,将打开图库。但它没有选择和上传任何图像。我还需要将上传的图像存储在链接上。&#34; Constants.BASE_URL +&#34; mobile_logins / create_event&#34;。我知道将数据发送到服务器的代码。但我不知道如何在服务器上存储图像。请帮忙..