Skip to content

Commit

Permalink
history fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc432341 committed May 12, 2021
1 parent 02646ff commit 46f0819
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/src/main/java/com/example/dhapp/DbManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public void addHistoryElement(String historyName) {
db.execSQL("INSERT INTO history (name) VALUES ('" + historyName + "')");
}

public void deleteHistoryElement(String historyverlauf) {
db.execSQL("DELETE FROM history WHERE name = '" + historyverlauf + "'");
}

public String[] outputStock() throws SQLException {

SQLiteDatabase db = getReadableDatabase();
Expand Down Expand Up @@ -108,8 +112,4 @@ public String[] getElements(String ColumnName, String TableName) {
cursor.close();
return resultValues;
}

public void deleteHistoryElement(int id) {
db.execSQL("DELETE FROM history WHERE historyID="+id);
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/example/dhapp/HistoryFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -13,6 +15,9 @@

public class HistoryFragment extends Fragment {

DbManager dbm;
TextView historyName;
Button deleteHistory;

@Nullable
@Override
Expand All @@ -27,6 +32,21 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

try {

dbm = new DbManager(getActivity());
String name;

historyName = view.findViewById(R.id.historyName);

name = historyName.getText().toString();
deleteHistory = view.findViewById(R.id.deleteHistoryButton);
deleteHistory.setOnClickListener(v -> {
try{
dbm.deleteHistoryElement(name);
}catch (Exception e){
e.printStackTrace();
}
});

RecyclerView recyclerView;

String[] HistoryName;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/dhapp/MyAdapterHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class MyViewHolder extends RecyclerView.ViewHolder {

public MyViewHolder(@NonNull View itemView) {
super(itemView);
stockNameView = itemView.findViewById(R.id.HistoryName);
stockNameView = itemView.findViewById(R.id.historyName);
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/my_history_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:layout_height="match_parent">

<TextView
android:id="@+id/HistoryName"
android:id="@+id/historyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
Expand All @@ -32,7 +32,7 @@
app:layout_constraintTop_toTopOf="parent" />

<ImageButton
android:id="@+id/imageButton2"
android:id="@+id/deleteHistoryButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="16dp"
Expand Down

0 comments on commit 46f0819

Please sign in to comment.