我试图将ListView添加到Fragment:
package zavrsni.android.app;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import zavrsni.android.app.ResultReceiverFromIS.Receiver;
import zavrsni.android.app.database.DatabaseHandler;
import zavrsni.android.app.service.GetAllNewData;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ToDo extends Fragment implements Receiver {
TextView newJobs;
TextView lastSync;
ResultReceiverFromIS mReceiver = new ResultReceiverFromIS(new Handler());
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = (LinearLayout) inflater.inflate(R.layout.todo, container,
false);
newJobs = (TextView) view.findViewById(R.id.webPrint);
lastSync = (TextView) view.findViewById(R.id.lastSync);
Button btnSync = (Button) view.findViewById(R.id.syncBtn);
mReceiver.setReceiver(this);
btnSync.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getActivity(), GetAllNewData.class);
i.putExtra("nameTag","sohail" );
i.putExtra("receiverTag", mReceiver);
getActivity().startService(i);
}
});
return view;
}
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
String print;
DatabaseHandler dbH = new DatabaseHandler(getActivity());
print = dbH.GetLastSync();
long start = Long.valueOf(print).longValue();
DateFormat df = new SimpleDateFormat("dd'.'MM'.'yyyy' , 'HH':'mm':'ss");
df.setTimeZone(TimeZone.getTimeZone("GMT+2"));
print = "Posljednja sinkronizacija: "+df.format(new Date(start));
lastSync.setText(print);
}
}
我想把ListView波纹管同步按钮。我尝试了一切,但我没有用。
有人可以扩展我的代码,并在片段中编写列表示例,将显示在同步按钮下方。
抱歉我的英语不好。
编辑:todo.xml
这够了吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/todo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/todo1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/syncBtn"
android:layout_width="wrap_content"
android:layout_height="33dp"
android:layout_gravity="right"
android:text="@string/sync"
android:textSize="10sp"
android:width="50dp" >
</Button>
<TextView
android:id="@+id/lastSync"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/lastSync"
android:textColor="@color/text_color"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>