android


how use ListView in Fragment Android


I have read many articles that explain how to use a ListView in Fragment, but I'm new programming android and I need help I can do that after pressing the button, display the information generated and almancenada within a variable publishes
public ConsNotas static [] list
Hola chicos, he leido muchos articulos que explican como usar un ListView en Fragment, pero soy nuevo en programacion android y necesito que me ayuden que puedo hacer para que luego de pulsar el boton, muestre la informacion generada y almancenada dentro de una variable publica
public static ConsNotas[] lista
public class Fragment1 extends Fragment {
Context context;
Boolean bFlagOpt;
public Fragment1(){}
#Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_fragment1, container, false);
final Spinner cmbTipoConsulta = (Spinner) v.findViewById(R.id.cmbTipoConsulta);
final Spinner cmbSemestre = (Spinner) v.findViewById(R.id.cmbSemestre);
final ListView lst = (ListView) v.findViewById(R.id.lstNotas);
String [] cTipoConsulta = getResources().getStringArray(R.array.CmbtpConsulta);
String [] cSemestre = getResources().getStringArray(R.array.cmbSemestre);
/* LLeno el combo de Tipo Consulta */
ArrayAdapter<String> LTRadapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, cTipoConsulta);
LTRadapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
cmbTipoConsulta.setAdapter(LTRadapter);
/* LLeno el combo de Tipo Consulta */
ArrayAdapter<String> LTRadapter2 = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, cSemestre);
LTRadapter2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
cmbSemestre.setAdapter(LTRadapter2);
Button upButton = (Button) v.findViewById(R.id.btnBuscar);
RadioGroup rdGruoup = (RadioGroup) v.findViewById(R.id.rdGroup1);
final RadioButton opGeneral = (RadioButton) v.findViewById(R.id.opGeneral);
final RadioButton opSemestre = (RadioButton) v.findViewById(R.id.opPorSemestre);
cmbSemestre.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Object iSemestre = parent.getItemAtPosition(pos);
varPub.iPosSemestre = pos;
switch (varPub.iPosSemestre) {
case 0:
varPub.sSemestre = "0";
break;
case 1:
varPub.sSemestre = "1";
break;
case 2:
varPub.sSemestre = "2";
break;
case 3:
varPub.sSemestre = "3";
break;
case 4:
varPub.sSemestre = "4";
break;
case 5:
varPub.sSemestre = "5";
break;
case 6:
varPub.sSemestre = "6";
break;
case 7:
varPub.sSemestre = "7";
break;
case 8:
varPub.sSemestre = "8";
break;
}
}
public void onNothingSelected(AdapterView<?> parent) {
varPub.sSemestre = "0"; //NINGUNO ELEGIDO
}
});
cmbTipoConsulta.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Object item = parent.getItemAtPosition(pos);
varPub.iPosTpConsulta = pos;
switch (varPub.iPosTpConsulta) {
case 0:
varPub.sTipoConsutla = "NING"; //NINGUNO ELEGIDO
break;
case 1:
varPub.sTipoConsutla = "NOTA"; //Notas General
//Log.i("NavigationView", iPosTpConsulta + " " + sTipoConsutla);
break;
case 2:
varPub.sTipoConsutla = "MAPR"; //Materias Aprobadas
Log.i("NavigationView", varPub.iPosTpConsulta + " " + varPub.sTipoConsutla);
break;
case 3:
varPub.sTipoConsutla = "MREP"; //Materias Reprobadas
//Log.i("NavigationView", iPosTpConsulta + " " + sTipoConsutla);
break;
case 4:
varPub.sTipoConsutla = "CING"; //Curso d Ingles
// Log.i("NavigationView", iPosTpConsulta + " " + sTipoConsutla);
break;
case 5:
varPub.sTipoConsutla = "COMP"; //CURSO DE COMPUTACION
//Log.i("NavigationView", iPosTpConsulta + " " + sTipoConsutla);
break;
}
}
public void onNothingSelected(AdapterView<?> parent) {
varPub.sTipoConsutla = "NING"; //NINGUNO ELEGIDO
}
});
bFlagOpt = true;
if (cmbSemestre.isEnabled()){
cmbSemestre.setEnabled(false);
}
rdGruoup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.opGeneral:
cmbSemestre.setEnabled(false);
bFlagOpt = true;
break;
case R.id.opPorSemestre:
cmbSemestre.setEnabled(true);
bFlagOpt = false;
break;
}
}
});
//boton
upButton.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
varPub var;
if (validadato(v)){
ConsultaNotas notas = new ConsultaNotas(getContext().getApplicationContext());
notas.execute();
if (varPub.bNotas){
}
}
}
});
// Inflate the layout for this fragment
return v;
}
public boolean validadato(View v){
boolean cancel = false;
View focusView = null;
RadioButton optSemestre, optGeneral;
if ( varPub.sTipoConsutla.equals("NING")) {
Toast.makeText(getActivity(), "Debe de elegir un Tipo de Consulta", Toast.LENGTH_LONG).show();
cancel = true;
}
if(bFlagOpt == false) {
if ( varPub.sSemestre.equals("0")) {
Toast.makeText(getActivity(), "Debe de elegir un semestre", Toast.LENGTH_LONG).show();
cancel = true;
}
}
if (cancel) {
return false;
}
else
{
return true;
}
}
}
It's the same as using it in activity.. the difference is the way you use findviewbyid which you correctly did. But you didn't use your listview on the code you've given which is the lst..

Related Links

Draw Lines perodically
Emalator and Phone Shows More Icons for one application?
How to pass String array to webservice using ksoap2?
Get values from a Activity with CheckBoxList to another Activity
Launch Android App with Specific Activity
Holding wifi locks in a foreground service
Android Spinner get selected value OnSelectedItemListener();
SQLite Connections & Locking
View overlapping using library components
How to connect to twitter with Oauth? (requesting easy code example)
Take image from SD card, compress it, and save it back to SD?
How can I check if emails can be sent from my phone?
App gettin NullPointerException missing view in Layout
ANDROID: Help, outofmemory bitmap exceeds budget size. how to recycle?
Fragments onCreateView() bundle. Where does it come from?
Define interfaces for Android Intents

Categories

HOME
azure-stream-analytics
facebook-oauth
paraview
apache-flink
webdriver
mysql-workbench
solaris
sublimetext
edge
web-hosting
spring-session
iis-6
rcloud
spin
google-chrome-app
endeca
openpyxl
github-enterprise
windows-ce
alamofire
mautic
ycsb
cmdb
code-generation
dynatrace
azure-iot-hub
alpacajs
esoteric-languages
dynamic-sql
microsoft-dynamics-nav
android-7.0-nougat
backpack-for-laravel
react-toolbox
joptionpane
onload
bulletphysics
android-sharedpreferences
android-maps
progress-bar
linked-data
comparable
user-defined-functions
sqsh
postback
kudu
complex-numbers
dumpbin
playstation-portable
rselenium
papaparse
openwhisk
vue-chartjs
pdw-file-browser
batching
video-capture
docfx
salesforce-communities
google-knowledge-graph
nohup
typesafe-config
signals-slots
watchface
sharp-snmp
android-checkbox
importerror
oim
double-click
textsum
mschart
remedy
aquamacs
skin
oozie-coordinator
flyout
ampps
filenet
choice
neon
x-tag
i386
eigenvector
xdoclet
mediametadataretriever
angular-ui-typeahead
spreadjs
phpwebsocket
ellucian-scribe
thread-sleep
grass
contentcontrol
spring-retry
linklabel
rate-limiting
poppler
vacuum
keyup
zend-currency
mass-assignment
dbaccess
webfinger
paw
named-parameters
wxformbuilder
conditionaltagsupport
visual-studio-express
kaleidoscope
time.h
cardreader
virtual-pc
zope.interface
cuda-gdb
appjs
usertype
infobright
matlab-load
umra
msr
binomial-heap
request-headers
lobo-cobra
sifr3
fail-fast-fail-early
sqlobject
flvplayback
information-management
movieplayer

Resources

Encrypt Message