Android에서 새로워 어떻게 작동하는지 이해하려고합니다. 조각을 동적으로로드하려고합니다. 4 개의 버튼이있는 레이아웃과 클릭 한 버튼에 따라 프레임 레이아웃 내에서 액티비티를로드하는 프레임 레이아웃이 있습니다. 활동 코드 :목록보기에 데이터가 없습니다. 조각이
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50sp"
android:background="#00BFF3">
<Button
android:id="@+id/teachers"
android:layout_width="180sp"
android:layout_height="25sp"
style="?attr/borderlessButtonStyle"
android:background="#00BFF3"
android:textColor="#ffffff"
android:textSize="18sp"
android:layout_marginTop="10sp"
android:text="Staff Directory"
android:textAlignment="viewStart"
android:layout_marginStart="15sp"
android:onClick="Teachers"/>
<Button
android:id="@+id/attendances"
android:layout_width="175sp"
android:layout_height="25sp"
style="?attr/borderlessButtonStyle"
android:background="#00BFF3"
android:textColor="#ffffff"
android:textSize="18sp"
android:layout_marginTop="10sp"
android:text="Attendance List"
android:textAlignment="viewStart"
android:layout_marginStart="185sp"
android:onClick="Attendances"/>
<Button
android:id="@+id/todayAttandance"
android:layout_width="190sp"
android:layout_height="25sp"
style="?attr/borderlessButtonStyle"
android:background="#00BFF3"
android:textColor="#ffffff"
android:textSize="18sp"
android:layout_marginTop="10sp"
android:text="Today Attendance"
android:textAlignment="viewStart"
android:layout_marginStart="355sp"
android:onClick="TodayAttendance"/>
<Button
android:id="@+id/students"
android:layout_width="150sp"
android:layout_height="25sp"
style="?attr/borderlessButtonStyle"
android:background="#00BFF3"
android:textColor="#ffffff"
android:textSize="18sp"
android:layout_marginTop="10sp"
android:text="Student List"
android:textAlignment="viewStart"
android:layout_marginStart="545sp"
android:onClick="Students"/>
</RelativeLayout>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_marginTop="10sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
목록보기 템플릿 :
이<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="40sp"
android:text="TextView"
android:layout_weight="1"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/classname"
android:layout_width="0dp"
android:layout_height="40sp"
android:text=""
android:layout_weight="1"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/fname"
android:layout_width="0dp"
android:layout_height="40sp"
android:text=""
android:layout_weight="1"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/fphone"
android:layout_width="0dp"
android:layout_height="40sp"
android:text=""
android:layout_weight="1"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
Activity.Java :
public class firstWindow extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_window);
}
public void Students(View v){
OpenWindow(1);
}
public void OpenWindow(int index){
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
studentFragment fragment = new studentFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}
}
조각 코드 :
public class studentFragment extends ListFragment implements iEvents<student> {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
student s = new student();
ArrayList<student> arraylist = new ArrayList<student>();
s.setName("Vikas");
s.setId(1);
s.setAddress("G-20, Arjun Nagar");
s.setPhone("9818899114");
arraylist.add(s);
studentAdapter simpleAdapter = new studentAdapter(getActivity().getApplicationContext(),arraylist);
setListAdapter(simpleAdapter);
}
@Override
public void Success(List<student> extenders) {
if(extenders!=null){
if(extenders.size()==1){
//may be a failure
student s = extenders.get(0);
if(s.getCode()==-1){
//error
return;
}
}
if(extenders.size() > 0){
//valid collection
// setContentView(R.layout.studentlistview);
ArrayList<student> arraylist = new ArrayList<student>(extenders);
context.get_context().setStudentList(extenders);
studentAdapter simpleAdapter = new studentAdapter(getActivity().getApplicationContext(),arraylist);
setListAdapter(simpleAdapter);
// setContentView(R.layout.activity_student_show_all);
}
}
}
@Override
public void Failure(List<student> extenders) {
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
////outState.putInt("curChoice", mCurCheckPosition);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
//showDetails(position);
student selectedItem = (student) context.get_context().getStudentList().get(position);
context.get_context().StudentHolder = selectedItem;
ShowDetails(selectedItem);
}
private void ShowDetails(student stu){
}
/**
* Helper function to show the details of a selected item, either by
* displaying a fragment in-place in the current UI, or starting a
* whole new activity in which it is displayed.
*/
void showDetails(int index) {
}
}
어댑터 코드 :하는 API에서 데이터를 다운로드 :
내가 디버깅 할 때public class studentAdapter extends ArrayAdapter<student> {
public studentAdapter(Context context, ArrayList<student> students) {
super(context, R.layout.studentlistview, students);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
student user = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.studentlistview, parent, true);
}
// Lookup view for data population
TextView name = (TextView) convertView.findViewById(R.id.name);
TextView className = (TextView) convertView.findViewById(R.id.classname);
TextView father = (TextView) convertView.findViewById(R.id.fname);
TextView fatherMobile = (TextView) convertView.findViewById(R.id.fphone);
name.setText(user.getName());
className.setText(user.getClassName());
father.setText(user.getFatherName());
fatherMobile.setText(user.getFatherPhone());
return convertView;
}
}
그래서,이 유형의 학생의 40 개 품목로드되었는지 보여 주지만보기가 나에게 보여줍니다 새로 고침되지 않습니다 : Screenshot of image
이보기가 값을로드하지만 것 같다 화면에 표시되는보기가 표시되지 않도록 값을로드하는보기와 다릅니다. 어떤 도움이 필요합니까? 당신이 당신의 목록 (40 개) 요소를 통해 올 보여주고 있다고 주장 때문에
먼저 Java 클래스 이름은 대문자로 시작해야하며 메소드는 소문자로 시작해야합니다. 어쨌든,'Success (List Extender)'가 어떻게 호출 되나요? 'executionList' 클래스는 어디에 있습니까? –
나는 코딩 표준에 대해 너무 혼란 스럽다. 나는 그것에 대해 연구 할 것이다. 내가 자바 녀석이 아니기 때문에 API에서 데이터를 다운로드하기 위해 레이어를 작성한 다음 해당 아키텍처에서 데이터를 다운로드 한 후 데이터 영역에서 성공 함수를 호출합니다. 건축물에는 많은 수업이있어서 모두 게시 할 수는 없습니다. 하지만이 부분은 잘 작동하고 있습니다. coz 독립 실행 형 활동으로 학생 목록을 작성하기 위해 테스트를 실시하고 결과를 잘로드했습니다. 나는 내가 이해하거나 찾지 못하는 원인이 될 수있는 매우 일반적인/멍청한 오류가 있다고 생각한다. –
응용 프로그램에 데이터를로드하는 데 라이브러리를 사용하지 못했습니다. ** context.get_context(). setStudentList (extenders); ** ?? 또는 ** executionList 실행 = 새 executionList <> (this); ** ??? 조금 설명 할 수 있겠 어! 그러나 최근에 자바를 시작하고 더 많은 도움이 필요하다고 생각합니다. 어쩌면 내가 그걸로 당신을 도울 수 ... –