How to hide other results and just show first result in ListView after Scanned QR Code












0















I'm developing Scan Update App that scan QR Code and update it to Database.



Here is my code for Update to Database.



private void updateDB() throws ClassNotFoundException, SQLException {
int OKcnt = 0;
int NotOKcnt = 0;
String shows = "";
Class.forName("org.postgresql.Driver");
Connection conn = null;
try {
conn = DriverManager.getConnection(
sp.getString("URL","jdbc:postgresql://localhost:5432/Test"),
sp.getString("User","Test"), sp.getString("Pass","Test")
);
for (String scanned : scannedList) {
String splits = scanned.split(",");
String show = "Show Table";
String table = "BedRegistration";
String set = "DocStatus";
String set2 = "IP";
String where = "Name";
String where2 = scanned;

show = splits[0].equals("") ? table :splits [0];
table = splits[1].equals("") ? table : splits[1];
where = splits[2].equals("") ? where : splits[2];
where2 = splits[3].equals("") ? where2 : splits[3];

show = show + ". ";
shows = shows + show ;

String SQL = "UPDATE " + table + " SET ";
String SQLWhere = " WHERE " + where + "='" + where2 + "'";
for (int i = 4; i < splits.length; i=i+2) {
set = splits[i].equals("") ? set : splits[i];
set2 = splits[i+1].equals("") ? set2 : splits[i+1];
SQL += set + " = '" + set2 + "', ";
}
SQL = SQL.substring(0, SQL.length() - 2);
SQL = SQL + SQLWhere;
Statement pstmt = conn.createStatement();

try {
int i = pstmt.executeUpdate(SQL);
System.out.println(SQL+"DB result = "+i);
OKcnt++;
} catch (SQLException e){
NotOKcnt++;
continue;
}
}


And here is my Scan QR Code code.



public void scanBar(View v) {
try {
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR,EAN_13,EAN_8,UPC_A,QR_CODE");
intent.putExtra("SAVE_HISTORY", false);

startActivityForResult(intent, 0);
} catch (ActivityNotFoundException anfe) {
showDialog(this, "No BarScanner Found", "Download a scanner code activity?", "Yes", "No").show();
}
}


How can i hide other results and just show first result which is String Show.



Coz i have tried someone codes from many sources including stackoverflow, tried to make 2 listview so 1 listview to store all the data and hide it and other listview to store and show just first result but it didn't work.



I have searched for two weeks before i decided to ask question at stackoverflow.



So i really confused right now. I hope someone can help me.
Thanks in advanced :)



PS: Sorry for my english.



Here is my listview and adapter code.



public static final String DB_CONNECTOR = "DB_Connector" ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.starprise.mobile.R.layout.activity_main);
Toolbar myToolbar = (Toolbar) findViewById(org.starprise.mobile.R.id.my_toolbar);
setSupportActionBar(myToolbar);
ActionBar ab = getSupportActionBar();
// Enable the Up button
ab.setDisplayHomeAsUpEnabled(true);

// We get the ListView component from the layout
ListView lv = (ListView) findViewById(R.id.ListView);
itemsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, scannedList);
lv.setAdapter(itemsAdapter);


Here is Button that i clicked to Update Database.



public void updateDB(View v) {
asyncDBHandling as = new asyncDBHandling(this);
as.execute(sp,scannedList);
//new asyncDBHandling().execute(sp,scannedList);
}


Here is Code to process after Scan QR Code.



public void onActivityResult(int requestCode, int resultCode, Intent intent) {

if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
scannedList.add(contents);
itemsAdapter.notifyDataSetChanged();









share|improve this question

























  • show your data rendering code

    – Har Kal
    Nov 22 '18 at 3:23











  • i mean listview and adapters code

    – Har Kal
    Nov 22 '18 at 3:23











  • I've edited my post @HarKal

    – Kevin The
    Nov 22 '18 at 3:36











  • just one more thing can you please log the results once what data you get

    – Har Kal
    Nov 22 '18 at 3:39











  • in your code you areb getting a single string

    – Har Kal
    Nov 22 '18 at 3:39
















0















I'm developing Scan Update App that scan QR Code and update it to Database.



Here is my code for Update to Database.



private void updateDB() throws ClassNotFoundException, SQLException {
int OKcnt = 0;
int NotOKcnt = 0;
String shows = "";
Class.forName("org.postgresql.Driver");
Connection conn = null;
try {
conn = DriverManager.getConnection(
sp.getString("URL","jdbc:postgresql://localhost:5432/Test"),
sp.getString("User","Test"), sp.getString("Pass","Test")
);
for (String scanned : scannedList) {
String splits = scanned.split(",");
String show = "Show Table";
String table = "BedRegistration";
String set = "DocStatus";
String set2 = "IP";
String where = "Name";
String where2 = scanned;

show = splits[0].equals("") ? table :splits [0];
table = splits[1].equals("") ? table : splits[1];
where = splits[2].equals("") ? where : splits[2];
where2 = splits[3].equals("") ? where2 : splits[3];

show = show + ". ";
shows = shows + show ;

String SQL = "UPDATE " + table + " SET ";
String SQLWhere = " WHERE " + where + "='" + where2 + "'";
for (int i = 4; i < splits.length; i=i+2) {
set = splits[i].equals("") ? set : splits[i];
set2 = splits[i+1].equals("") ? set2 : splits[i+1];
SQL += set + " = '" + set2 + "', ";
}
SQL = SQL.substring(0, SQL.length() - 2);
SQL = SQL + SQLWhere;
Statement pstmt = conn.createStatement();

try {
int i = pstmt.executeUpdate(SQL);
System.out.println(SQL+"DB result = "+i);
OKcnt++;
} catch (SQLException e){
NotOKcnt++;
continue;
}
}


And here is my Scan QR Code code.



public void scanBar(View v) {
try {
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR,EAN_13,EAN_8,UPC_A,QR_CODE");
intent.putExtra("SAVE_HISTORY", false);

startActivityForResult(intent, 0);
} catch (ActivityNotFoundException anfe) {
showDialog(this, "No BarScanner Found", "Download a scanner code activity?", "Yes", "No").show();
}
}


How can i hide other results and just show first result which is String Show.



Coz i have tried someone codes from many sources including stackoverflow, tried to make 2 listview so 1 listview to store all the data and hide it and other listview to store and show just first result but it didn't work.



I have searched for two weeks before i decided to ask question at stackoverflow.



So i really confused right now. I hope someone can help me.
Thanks in advanced :)



PS: Sorry for my english.



Here is my listview and adapter code.



public static final String DB_CONNECTOR = "DB_Connector" ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.starprise.mobile.R.layout.activity_main);
Toolbar myToolbar = (Toolbar) findViewById(org.starprise.mobile.R.id.my_toolbar);
setSupportActionBar(myToolbar);
ActionBar ab = getSupportActionBar();
// Enable the Up button
ab.setDisplayHomeAsUpEnabled(true);

// We get the ListView component from the layout
ListView lv = (ListView) findViewById(R.id.ListView);
itemsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, scannedList);
lv.setAdapter(itemsAdapter);


Here is Button that i clicked to Update Database.



public void updateDB(View v) {
asyncDBHandling as = new asyncDBHandling(this);
as.execute(sp,scannedList);
//new asyncDBHandling().execute(sp,scannedList);
}


Here is Code to process after Scan QR Code.



public void onActivityResult(int requestCode, int resultCode, Intent intent) {

if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
scannedList.add(contents);
itemsAdapter.notifyDataSetChanged();









share|improve this question

























  • show your data rendering code

    – Har Kal
    Nov 22 '18 at 3:23











  • i mean listview and adapters code

    – Har Kal
    Nov 22 '18 at 3:23











  • I've edited my post @HarKal

    – Kevin The
    Nov 22 '18 at 3:36











  • just one more thing can you please log the results once what data you get

    – Har Kal
    Nov 22 '18 at 3:39











  • in your code you areb getting a single string

    – Har Kal
    Nov 22 '18 at 3:39














0












0








0








I'm developing Scan Update App that scan QR Code and update it to Database.



Here is my code for Update to Database.



private void updateDB() throws ClassNotFoundException, SQLException {
int OKcnt = 0;
int NotOKcnt = 0;
String shows = "";
Class.forName("org.postgresql.Driver");
Connection conn = null;
try {
conn = DriverManager.getConnection(
sp.getString("URL","jdbc:postgresql://localhost:5432/Test"),
sp.getString("User","Test"), sp.getString("Pass","Test")
);
for (String scanned : scannedList) {
String splits = scanned.split(",");
String show = "Show Table";
String table = "BedRegistration";
String set = "DocStatus";
String set2 = "IP";
String where = "Name";
String where2 = scanned;

show = splits[0].equals("") ? table :splits [0];
table = splits[1].equals("") ? table : splits[1];
where = splits[2].equals("") ? where : splits[2];
where2 = splits[3].equals("") ? where2 : splits[3];

show = show + ". ";
shows = shows + show ;

String SQL = "UPDATE " + table + " SET ";
String SQLWhere = " WHERE " + where + "='" + where2 + "'";
for (int i = 4; i < splits.length; i=i+2) {
set = splits[i].equals("") ? set : splits[i];
set2 = splits[i+1].equals("") ? set2 : splits[i+1];
SQL += set + " = '" + set2 + "', ";
}
SQL = SQL.substring(0, SQL.length() - 2);
SQL = SQL + SQLWhere;
Statement pstmt = conn.createStatement();

try {
int i = pstmt.executeUpdate(SQL);
System.out.println(SQL+"DB result = "+i);
OKcnt++;
} catch (SQLException e){
NotOKcnt++;
continue;
}
}


And here is my Scan QR Code code.



public void scanBar(View v) {
try {
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR,EAN_13,EAN_8,UPC_A,QR_CODE");
intent.putExtra("SAVE_HISTORY", false);

startActivityForResult(intent, 0);
} catch (ActivityNotFoundException anfe) {
showDialog(this, "No BarScanner Found", "Download a scanner code activity?", "Yes", "No").show();
}
}


How can i hide other results and just show first result which is String Show.



Coz i have tried someone codes from many sources including stackoverflow, tried to make 2 listview so 1 listview to store all the data and hide it and other listview to store and show just first result but it didn't work.



I have searched for two weeks before i decided to ask question at stackoverflow.



So i really confused right now. I hope someone can help me.
Thanks in advanced :)



PS: Sorry for my english.



Here is my listview and adapter code.



public static final String DB_CONNECTOR = "DB_Connector" ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.starprise.mobile.R.layout.activity_main);
Toolbar myToolbar = (Toolbar) findViewById(org.starprise.mobile.R.id.my_toolbar);
setSupportActionBar(myToolbar);
ActionBar ab = getSupportActionBar();
// Enable the Up button
ab.setDisplayHomeAsUpEnabled(true);

// We get the ListView component from the layout
ListView lv = (ListView) findViewById(R.id.ListView);
itemsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, scannedList);
lv.setAdapter(itemsAdapter);


Here is Button that i clicked to Update Database.



public void updateDB(View v) {
asyncDBHandling as = new asyncDBHandling(this);
as.execute(sp,scannedList);
//new asyncDBHandling().execute(sp,scannedList);
}


Here is Code to process after Scan QR Code.



public void onActivityResult(int requestCode, int resultCode, Intent intent) {

if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
scannedList.add(contents);
itemsAdapter.notifyDataSetChanged();









share|improve this question
















I'm developing Scan Update App that scan QR Code and update it to Database.



Here is my code for Update to Database.



private void updateDB() throws ClassNotFoundException, SQLException {
int OKcnt = 0;
int NotOKcnt = 0;
String shows = "";
Class.forName("org.postgresql.Driver");
Connection conn = null;
try {
conn = DriverManager.getConnection(
sp.getString("URL","jdbc:postgresql://localhost:5432/Test"),
sp.getString("User","Test"), sp.getString("Pass","Test")
);
for (String scanned : scannedList) {
String splits = scanned.split(",");
String show = "Show Table";
String table = "BedRegistration";
String set = "DocStatus";
String set2 = "IP";
String where = "Name";
String where2 = scanned;

show = splits[0].equals("") ? table :splits [0];
table = splits[1].equals("") ? table : splits[1];
where = splits[2].equals("") ? where : splits[2];
where2 = splits[3].equals("") ? where2 : splits[3];

show = show + ". ";
shows = shows + show ;

String SQL = "UPDATE " + table + " SET ";
String SQLWhere = " WHERE " + where + "='" + where2 + "'";
for (int i = 4; i < splits.length; i=i+2) {
set = splits[i].equals("") ? set : splits[i];
set2 = splits[i+1].equals("") ? set2 : splits[i+1];
SQL += set + " = '" + set2 + "', ";
}
SQL = SQL.substring(0, SQL.length() - 2);
SQL = SQL + SQLWhere;
Statement pstmt = conn.createStatement();

try {
int i = pstmt.executeUpdate(SQL);
System.out.println(SQL+"DB result = "+i);
OKcnt++;
} catch (SQLException e){
NotOKcnt++;
continue;
}
}


And here is my Scan QR Code code.



public void scanBar(View v) {
try {
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR,EAN_13,EAN_8,UPC_A,QR_CODE");
intent.putExtra("SAVE_HISTORY", false);

startActivityForResult(intent, 0);
} catch (ActivityNotFoundException anfe) {
showDialog(this, "No BarScanner Found", "Download a scanner code activity?", "Yes", "No").show();
}
}


How can i hide other results and just show first result which is String Show.



Coz i have tried someone codes from many sources including stackoverflow, tried to make 2 listview so 1 listview to store all the data and hide it and other listview to store and show just first result but it didn't work.



I have searched for two weeks before i decided to ask question at stackoverflow.



So i really confused right now. I hope someone can help me.
Thanks in advanced :)



PS: Sorry for my english.



Here is my listview and adapter code.



public static final String DB_CONNECTOR = "DB_Connector" ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.starprise.mobile.R.layout.activity_main);
Toolbar myToolbar = (Toolbar) findViewById(org.starprise.mobile.R.id.my_toolbar);
setSupportActionBar(myToolbar);
ActionBar ab = getSupportActionBar();
// Enable the Up button
ab.setDisplayHomeAsUpEnabled(true);

// We get the ListView component from the layout
ListView lv = (ListView) findViewById(R.id.ListView);
itemsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, scannedList);
lv.setAdapter(itemsAdapter);


Here is Button that i clicked to Update Database.



public void updateDB(View v) {
asyncDBHandling as = new asyncDBHandling(this);
as.execute(sp,scannedList);
//new asyncDBHandling().execute(sp,scannedList);
}


Here is Code to process after Scan QR Code.



public void onActivityResult(int requestCode, int resultCode, Intent intent) {

if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
scannedList.add(contents);
itemsAdapter.notifyDataSetChanged();






java android-studio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 3:36







Kevin The

















asked Nov 22 '18 at 3:19









Kevin TheKevin The

34




34













  • show your data rendering code

    – Har Kal
    Nov 22 '18 at 3:23











  • i mean listview and adapters code

    – Har Kal
    Nov 22 '18 at 3:23











  • I've edited my post @HarKal

    – Kevin The
    Nov 22 '18 at 3:36











  • just one more thing can you please log the results once what data you get

    – Har Kal
    Nov 22 '18 at 3:39











  • in your code you areb getting a single string

    – Har Kal
    Nov 22 '18 at 3:39



















  • show your data rendering code

    – Har Kal
    Nov 22 '18 at 3:23











  • i mean listview and adapters code

    – Har Kal
    Nov 22 '18 at 3:23











  • I've edited my post @HarKal

    – Kevin The
    Nov 22 '18 at 3:36











  • just one more thing can you please log the results once what data you get

    – Har Kal
    Nov 22 '18 at 3:39











  • in your code you areb getting a single string

    – Har Kal
    Nov 22 '18 at 3:39

















show your data rendering code

– Har Kal
Nov 22 '18 at 3:23





show your data rendering code

– Har Kal
Nov 22 '18 at 3:23













i mean listview and adapters code

– Har Kal
Nov 22 '18 at 3:23





i mean listview and adapters code

– Har Kal
Nov 22 '18 at 3:23













I've edited my post @HarKal

– Kevin The
Nov 22 '18 at 3:36





I've edited my post @HarKal

– Kevin The
Nov 22 '18 at 3:36













just one more thing can you please log the results once what data you get

– Har Kal
Nov 22 '18 at 3:39





just one more thing can you please log the results once what data you get

– Har Kal
Nov 22 '18 at 3:39













in your code you areb getting a single string

– Har Kal
Nov 22 '18 at 3:39





in your code you areb getting a single string

– Har Kal
Nov 22 '18 at 3:39












2 Answers
2






active

oldest

votes


















0














if the format of your results is always constant then you can rely on this code



public void onActivityResult(int requestCode, int resultCode, Intent intent) {

if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
String first_result = contents.substring( 0, contents.indexOf(","));

scannedList.add(first_result);
itemsAdapter.notifyDataSetChanged();
}
}
}


leme know if some problem occurrs






share|improve this answer
























  • Woah thank you, i will try this :)

    – Kevin The
    Nov 22 '18 at 4:10











  • accept it if it works. it ll help me :)

    – Har Kal
    Nov 22 '18 at 4:10











  • of course i will if it works :)

    – Kevin The
    Nov 22 '18 at 4:12











  • I just tested it and it doesn't show in the ListView, just blank

    – Kevin The
    Nov 23 '18 at 3:42











  • just try logging the data with Log.i("whole data : ", contents); and Log.i("first data : ", first_result); in onActivityResults and show me the values please

    – Har Kal
    Nov 23 '18 at 5:31



















-1














In your ListView Adapter, you will probably have a List, ArrayList or any object that grows in size from which your ListView renders it's data.



What determines how many of the data in the ArrayList or List to render is the return value of the getCount() method.



Do something of the sort



package com.fz5.emminent17.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.Collections;

/**
* Created by Francis Ilechukwu 20/11/2017.
*/

public class SearchResult Adapter extends BaseAdapter {

private ArrayList<String> searchResults = new ArrayList<>();
private boolean showOnlyFirst = false;

public FacultyAdapter(String searchResults) {
Collections.addAll(this.searchResults, searchResults);
}

public void setShouldShowFirstOnly(boolean showOnlyFirst) {
this.showOnlyFirst = showOnlyFirst;
}

@Override
public int getCount() {
if (showOnlyFirst) {
return 1;
}
return searchResults.size();
}

@Override
public Object getItem(int i) {
return searchResults.get(i);
}

@Override
public long getItemId(int i) {
return 0;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
// Your Normal getView implementation
}
}


Notice the showOnlyFirst boolean, it's a control variable to use on case you want to show all results later or by the press of a button.



However, to show only first, set it to true.






share|improve this answer
























  • Okay thank you i will try this too :)

    – Kevin The
    Nov 22 '18 at 4:12











  • Any reason for the downvote?

    – francis994
    Nov 24 '18 at 2:54











  • It was not me who downvote your comment @francis994

    – Kevin The
    Nov 26 '18 at 3:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423396%2fhow-to-hide-other-results-and-just-show-first-result-in-listview-after-scanned-q%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














if the format of your results is always constant then you can rely on this code



public void onActivityResult(int requestCode, int resultCode, Intent intent) {

if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
String first_result = contents.substring( 0, contents.indexOf(","));

scannedList.add(first_result);
itemsAdapter.notifyDataSetChanged();
}
}
}


leme know if some problem occurrs






share|improve this answer
























  • Woah thank you, i will try this :)

    – Kevin The
    Nov 22 '18 at 4:10











  • accept it if it works. it ll help me :)

    – Har Kal
    Nov 22 '18 at 4:10











  • of course i will if it works :)

    – Kevin The
    Nov 22 '18 at 4:12











  • I just tested it and it doesn't show in the ListView, just blank

    – Kevin The
    Nov 23 '18 at 3:42











  • just try logging the data with Log.i("whole data : ", contents); and Log.i("first data : ", first_result); in onActivityResults and show me the values please

    – Har Kal
    Nov 23 '18 at 5:31
















0














if the format of your results is always constant then you can rely on this code



public void onActivityResult(int requestCode, int resultCode, Intent intent) {

if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
String first_result = contents.substring( 0, contents.indexOf(","));

scannedList.add(first_result);
itemsAdapter.notifyDataSetChanged();
}
}
}


leme know if some problem occurrs






share|improve this answer
























  • Woah thank you, i will try this :)

    – Kevin The
    Nov 22 '18 at 4:10











  • accept it if it works. it ll help me :)

    – Har Kal
    Nov 22 '18 at 4:10











  • of course i will if it works :)

    – Kevin The
    Nov 22 '18 at 4:12











  • I just tested it and it doesn't show in the ListView, just blank

    – Kevin The
    Nov 23 '18 at 3:42











  • just try logging the data with Log.i("whole data : ", contents); and Log.i("first data : ", first_result); in onActivityResults and show me the values please

    – Har Kal
    Nov 23 '18 at 5:31














0












0








0







if the format of your results is always constant then you can rely on this code



public void onActivityResult(int requestCode, int resultCode, Intent intent) {

if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
String first_result = contents.substring( 0, contents.indexOf(","));

scannedList.add(first_result);
itemsAdapter.notifyDataSetChanged();
}
}
}


leme know if some problem occurrs






share|improve this answer













if the format of your results is always constant then you can rely on this code



public void onActivityResult(int requestCode, int resultCode, Intent intent) {

if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
String first_result = contents.substring( 0, contents.indexOf(","));

scannedList.add(first_result);
itemsAdapter.notifyDataSetChanged();
}
}
}


leme know if some problem occurrs







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 4:04









Har KalHar Kal

612414




612414













  • Woah thank you, i will try this :)

    – Kevin The
    Nov 22 '18 at 4:10











  • accept it if it works. it ll help me :)

    – Har Kal
    Nov 22 '18 at 4:10











  • of course i will if it works :)

    – Kevin The
    Nov 22 '18 at 4:12











  • I just tested it and it doesn't show in the ListView, just blank

    – Kevin The
    Nov 23 '18 at 3:42











  • just try logging the data with Log.i("whole data : ", contents); and Log.i("first data : ", first_result); in onActivityResults and show me the values please

    – Har Kal
    Nov 23 '18 at 5:31



















  • Woah thank you, i will try this :)

    – Kevin The
    Nov 22 '18 at 4:10











  • accept it if it works. it ll help me :)

    – Har Kal
    Nov 22 '18 at 4:10











  • of course i will if it works :)

    – Kevin The
    Nov 22 '18 at 4:12











  • I just tested it and it doesn't show in the ListView, just blank

    – Kevin The
    Nov 23 '18 at 3:42











  • just try logging the data with Log.i("whole data : ", contents); and Log.i("first data : ", first_result); in onActivityResults and show me the values please

    – Har Kal
    Nov 23 '18 at 5:31

















Woah thank you, i will try this :)

– Kevin The
Nov 22 '18 at 4:10





Woah thank you, i will try this :)

– Kevin The
Nov 22 '18 at 4:10













accept it if it works. it ll help me :)

– Har Kal
Nov 22 '18 at 4:10





accept it if it works. it ll help me :)

– Har Kal
Nov 22 '18 at 4:10













of course i will if it works :)

– Kevin The
Nov 22 '18 at 4:12





of course i will if it works :)

– Kevin The
Nov 22 '18 at 4:12













I just tested it and it doesn't show in the ListView, just blank

– Kevin The
Nov 23 '18 at 3:42





I just tested it and it doesn't show in the ListView, just blank

– Kevin The
Nov 23 '18 at 3:42













just try logging the data with Log.i("whole data : ", contents); and Log.i("first data : ", first_result); in onActivityResults and show me the values please

– Har Kal
Nov 23 '18 at 5:31





just try logging the data with Log.i("whole data : ", contents); and Log.i("first data : ", first_result); in onActivityResults and show me the values please

– Har Kal
Nov 23 '18 at 5:31













-1














In your ListView Adapter, you will probably have a List, ArrayList or any object that grows in size from which your ListView renders it's data.



What determines how many of the data in the ArrayList or List to render is the return value of the getCount() method.



Do something of the sort



package com.fz5.emminent17.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.Collections;

/**
* Created by Francis Ilechukwu 20/11/2017.
*/

public class SearchResult Adapter extends BaseAdapter {

private ArrayList<String> searchResults = new ArrayList<>();
private boolean showOnlyFirst = false;

public FacultyAdapter(String searchResults) {
Collections.addAll(this.searchResults, searchResults);
}

public void setShouldShowFirstOnly(boolean showOnlyFirst) {
this.showOnlyFirst = showOnlyFirst;
}

@Override
public int getCount() {
if (showOnlyFirst) {
return 1;
}
return searchResults.size();
}

@Override
public Object getItem(int i) {
return searchResults.get(i);
}

@Override
public long getItemId(int i) {
return 0;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
// Your Normal getView implementation
}
}


Notice the showOnlyFirst boolean, it's a control variable to use on case you want to show all results later or by the press of a button.



However, to show only first, set it to true.






share|improve this answer
























  • Okay thank you i will try this too :)

    – Kevin The
    Nov 22 '18 at 4:12











  • Any reason for the downvote?

    – francis994
    Nov 24 '18 at 2:54











  • It was not me who downvote your comment @francis994

    – Kevin The
    Nov 26 '18 at 3:31
















-1














In your ListView Adapter, you will probably have a List, ArrayList or any object that grows in size from which your ListView renders it's data.



What determines how many of the data in the ArrayList or List to render is the return value of the getCount() method.



Do something of the sort



package com.fz5.emminent17.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.Collections;

/**
* Created by Francis Ilechukwu 20/11/2017.
*/

public class SearchResult Adapter extends BaseAdapter {

private ArrayList<String> searchResults = new ArrayList<>();
private boolean showOnlyFirst = false;

public FacultyAdapter(String searchResults) {
Collections.addAll(this.searchResults, searchResults);
}

public void setShouldShowFirstOnly(boolean showOnlyFirst) {
this.showOnlyFirst = showOnlyFirst;
}

@Override
public int getCount() {
if (showOnlyFirst) {
return 1;
}
return searchResults.size();
}

@Override
public Object getItem(int i) {
return searchResults.get(i);
}

@Override
public long getItemId(int i) {
return 0;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
// Your Normal getView implementation
}
}


Notice the showOnlyFirst boolean, it's a control variable to use on case you want to show all results later or by the press of a button.



However, to show only first, set it to true.






share|improve this answer
























  • Okay thank you i will try this too :)

    – Kevin The
    Nov 22 '18 at 4:12











  • Any reason for the downvote?

    – francis994
    Nov 24 '18 at 2:54











  • It was not me who downvote your comment @francis994

    – Kevin The
    Nov 26 '18 at 3:31














-1












-1








-1







In your ListView Adapter, you will probably have a List, ArrayList or any object that grows in size from which your ListView renders it's data.



What determines how many of the data in the ArrayList or List to render is the return value of the getCount() method.



Do something of the sort



package com.fz5.emminent17.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.Collections;

/**
* Created by Francis Ilechukwu 20/11/2017.
*/

public class SearchResult Adapter extends BaseAdapter {

private ArrayList<String> searchResults = new ArrayList<>();
private boolean showOnlyFirst = false;

public FacultyAdapter(String searchResults) {
Collections.addAll(this.searchResults, searchResults);
}

public void setShouldShowFirstOnly(boolean showOnlyFirst) {
this.showOnlyFirst = showOnlyFirst;
}

@Override
public int getCount() {
if (showOnlyFirst) {
return 1;
}
return searchResults.size();
}

@Override
public Object getItem(int i) {
return searchResults.get(i);
}

@Override
public long getItemId(int i) {
return 0;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
// Your Normal getView implementation
}
}


Notice the showOnlyFirst boolean, it's a control variable to use on case you want to show all results later or by the press of a button.



However, to show only first, set it to true.






share|improve this answer













In your ListView Adapter, you will probably have a List, ArrayList or any object that grows in size from which your ListView renders it's data.



What determines how many of the data in the ArrayList or List to render is the return value of the getCount() method.



Do something of the sort



package com.fz5.emminent17.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.Collections;

/**
* Created by Francis Ilechukwu 20/11/2017.
*/

public class SearchResult Adapter extends BaseAdapter {

private ArrayList<String> searchResults = new ArrayList<>();
private boolean showOnlyFirst = false;

public FacultyAdapter(String searchResults) {
Collections.addAll(this.searchResults, searchResults);
}

public void setShouldShowFirstOnly(boolean showOnlyFirst) {
this.showOnlyFirst = showOnlyFirst;
}

@Override
public int getCount() {
if (showOnlyFirst) {
return 1;
}
return searchResults.size();
}

@Override
public Object getItem(int i) {
return searchResults.get(i);
}

@Override
public long getItemId(int i) {
return 0;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
// Your Normal getView implementation
}
}


Notice the showOnlyFirst boolean, it's a control variable to use on case you want to show all results later or by the press of a button.



However, to show only first, set it to true.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 4:08









francis994francis994

495




495













  • Okay thank you i will try this too :)

    – Kevin The
    Nov 22 '18 at 4:12











  • Any reason for the downvote?

    – francis994
    Nov 24 '18 at 2:54











  • It was not me who downvote your comment @francis994

    – Kevin The
    Nov 26 '18 at 3:31



















  • Okay thank you i will try this too :)

    – Kevin The
    Nov 22 '18 at 4:12











  • Any reason for the downvote?

    – francis994
    Nov 24 '18 at 2:54











  • It was not me who downvote your comment @francis994

    – Kevin The
    Nov 26 '18 at 3:31

















Okay thank you i will try this too :)

– Kevin The
Nov 22 '18 at 4:12





Okay thank you i will try this too :)

– Kevin The
Nov 22 '18 at 4:12













Any reason for the downvote?

– francis994
Nov 24 '18 at 2:54





Any reason for the downvote?

– francis994
Nov 24 '18 at 2:54













It was not me who downvote your comment @francis994

– Kevin The
Nov 26 '18 at 3:31





It was not me who downvote your comment @francis994

– Kevin The
Nov 26 '18 at 3:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423396%2fhow-to-hide-other-results-and-just-show-first-result-in-listview-after-scanned-q%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]