Refactor
This commit is contained in:
parent
7e4e885fe0
commit
4b720c3a33
@ -0,0 +1,53 @@
|
||||
package com.example.ueberwachungssystem.Fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.example.ueberwachungssystem.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VideoFileFragment extends Fragment {
|
||||
|
||||
private ListView listView;
|
||||
private ArrayAdapter<String> adapter;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.video_file_fragment, container, false);
|
||||
|
||||
listView = rootView.findViewById(R.id.listView);
|
||||
adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, getData());
|
||||
listView.setAdapter(adapter);
|
||||
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
// Handle item click event here
|
||||
String selectedItem = adapter.getItem(position);
|
||||
Toast.makeText(requireContext(), selectedItem, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private List<String> getData() {
|
||||
// Add your data source here, e.g., an array or a list
|
||||
List<String> data = new ArrayList<>();
|
||||
data.add("Item 1");
|
||||
data.add("Item 2");
|
||||
data.add("Item 3");
|
||||
return data;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.example.ueberwachungssystem;
|
||||
|
||||
import androidx.camera.core.ExperimentalGetImage;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@ -16,7 +17,10 @@ import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
@ -25,6 +29,9 @@ import com.example.ueberwachungssystem.Fragments.Fragment1;
|
||||
import com.example.ueberwachungssystem.Fragments.Fragment2;
|
||||
import com.example.ueberwachungssystem.Detection.DetectorService;
|
||||
import com.example.ueberwachungssystem.Fragments.Fragment3;
|
||||
import com.example.ueberwachungssystem.Fragments.VideoFileFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ExperimentalGetImage
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
@ -36,6 +43,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private Fragment1 fragment1;
|
||||
private Fragment2 fragment2;
|
||||
private Fragment3 fragment3;
|
||||
private VideoFileFragment videoFileFragment = new VideoFileFragment();
|
||||
private DetectorService detectorService = new DetectorService();
|
||||
int num = 0;
|
||||
//Textviews
|
||||
@ -185,7 +193,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public void onClickZeigeFragment2(View view) {
|
||||
Button button = (Button) view;
|
||||
zeigeFragment(fragment2.erstellen("Hier stehen dann die Videos"));
|
||||
//zeigeFragment(fragment2.erstellen("Hier stehen dann die Videos"));
|
||||
zeigeFragment(videoFileFragment);
|
||||
}
|
||||
public void onClickZeigeFragment3(View view) {
|
||||
Button button = (Button) view;
|
||||
|
@ -0,0 +1,53 @@
|
||||
package com.example.ueberwachungssystem;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VideoAdapter extends ArrayAdapter<String> {
|
||||
|
||||
private List<String> fileList;
|
||||
private OnFileClickListener listener;
|
||||
|
||||
public VideoAdapter (Context context, List<String> fileList, OnFileClickListener listener) {
|
||||
super(context, 0, fileList);
|
||||
this.fileList = fileList;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
if (convertView == null) {
|
||||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_file, parent, false);
|
||||
}
|
||||
|
||||
TextView fileNameText = convertView.findViewById(R.id.file_name_text);
|
||||
final String fileName = fileList.get(position);
|
||||
fileNameText.setText(fileName);
|
||||
|
||||
convertView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
listener.onFileClick(fileName);
|
||||
listener.onFileClick(fileName);
|
||||
}
|
||||
});
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public interface OnFileClickListener {
|
||||
View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState);
|
||||
|
||||
void onFileClick(String fileName);
|
||||
}
|
||||
}
|
@ -125,5 +125,9 @@
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
-->
|
||||
<ListView
|
||||
android:id = "@+id/listView"
|
||||
android:layout_width = "wrap_content"
|
||||
android:layout_height = "wrap_content"/>
|
||||
|
||||
</RelativeLayout>
|
17
app/src/main/res/layout/list_item_file.xml
Normal file
17
app/src/main/res/layout/list_item_file.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- list_item_file.xml -->
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/file_name_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:padding="8dp"
|
||||
tools:ignore="MissingConstraints" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
16
app/src/main/res/layout/video_file_fragment.xml
Normal file
16
app/src/main/res/layout/video_file_fragment.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:background="@android:color/holo_blue_light">
|
||||
|
||||
<ListView
|
||||
android:id = "@+id/listView"
|
||||
android:layout_width = "wrap_content"
|
||||
android:layout_height = "wrap_content"
|
||||
tools:ignore="MissingConstraints" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user