2
I’m building a sales app where a user will publish their product with: image, price, description and value.
I can list the photo all right but I can’t put a title and the other descriptions
Here’s my list and my Adapter.
public class OfertasAdapter extends ArrayAdapter<ParseObject> {
private Context context;
private ArrayList<ParseObject> publicacoes;
public OfertasAdapter(Context c, ArrayList<ParseObject> objects) {
super(c, 0, objects);
this.context = c;
this.publicacoes = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
//Inicializa objeto para montagem do layout
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
//Monta a view a partir do xml
view = inflater.inflate(R.layout.lista_publicacoes, parent, false);
}
//Verifica se existe postagens
if (publicacoes.size() > 0) {
//Recupera componentes da tela
ImageView imagemPostagem = (ImageView) view.findViewById(R.id.image_lista_publicacoes);
ParseObject parseObject = publicacoes.get(position);
//parseObject.getParseFile( "imagem" );
Picasso.with(context)
.load( parseObject.getParseFile( "imagem" ).getUrl() )
.fit()
.into( imagemPostagem );
}
return view;
}
}
this is the process of saving the image in the database
public class PublicarOfertasActivity extends AppCompatActivity {
private ImageView botaoPublicar;
private ViewPager viewPager;
private Button botaoPublicar2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_publicar_ofertas);
botaoPublicar = (ImageView) findViewById(R.id.imagePublicar);
viewPager = (ViewPager) findViewById(R.id.view_pager_main);
/*configurar adapter novo
TabsAdapter tabsAdapter = new TabsAdapter(getSupportFragmentManager(),this);
viewPager.setAdapter(tabsAdapter);*/
botaoPublicar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
publicarOfertas();
}
});
}
private void publicarOfertas() {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//testar o processo de retorno dos dados
if (requestCode == 1 && resultCode == RESULT_OK && data != null) {
//Recuperar local do recurso
Uri localImagemSelecionada = data.getData();
//Recupera a imagem do local que foi selecionada
try {
Bitmap imagem = MediaStore.Images.Media.getBitmap(getContentResolver(), localImagemSelecionada);
/*
Comprimir imagem no formato PNG
*/
ByteArrayOutputStream stream = new ByteArrayOutputStream();
imagem.compress(Bitmap.CompressFormat.PNG, 75, stream);
/*Comprimir imagem no formato JPG!!!
*/
ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
imagem.compress(Bitmap.CompressFormat.JPEG, 75, stream2);
/*Cria 2 Arrays de Bytes da imagem tanto PNG quanto JPEG
*/
byte[] byteArray = stream.toByteArray();
byte[] byteArray2 = stream2.toByteArray();
/*Cria arquivos com formato proprio do Parse para PNG e JPEG
*/
SimpleDateFormat dateFormat = new SimpleDateFormat("ddmmaaaahhmmss");
String nomeImagem = dateFormat.format(new Date());
ParseFile arquivoParse = new ParseFile(nomeImagem + "imagem.png", byteArray);
ParseFile arquivoParse2 = new ParseFile(nomeImagem + "imagem.jpeg", byteArray2);
/*Monta um objeto para salvar no Parse
*/
ParseObject parseObject = new ParseObject("Imagem");
parseObject.put("username", ParseUser.getCurrentUser().getUsername());
/*Atribui 2 entradas de dados no objeto "imagem", para PNG e JPEG
*/
parseObject.put("imagem", arquivoParse);
parseObject.put("imagem", arquivoParse2);
//Salvar os dados
parseObject.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {//Sucesso
Toast.makeText(getApplicationContext(), "Sua imagem foi postada!", Toast.LENGTH_LONG).show();
/* TabsAdapter adapterNovo = (TabsAdapter) viewPager.getAdapter();
OfertasDoDia ofertasDoDiaNovo =(OfertasDoDia) adapterNovo.getFragment(1);
ofertasDoDiaNovo.atualizaPublicacoes();*/
} else {//Erro
Toast.makeText(getApplicationContext(), "Erro ao postar sua imagem, tente novamente!",
Toast.LENGTH_LONG).show();
}
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}
and here I list the images in Fragment
public class OfertasDoDia extends Fragment {
private ArrayList<ParseObject> publicacoes;
private ListView listView;
private ArrayAdapter<ParseObject> adapter;
private ParseQuery<ParseObject> recuperaImagem;
public OfertasDoDia() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_ofertas_do_dia, container, false);
//montar listview e adapter
publicacoes = new ArrayList<>();
listView = (ListView) view.findViewById(R.id.list_publicacoes);
adapter= new OfertasAdapter(getActivity(),publicacoes);
listView.setAdapter(adapter);
//recupera postagens
getPublicacoes();
return view;
}
private void getPublicacoes(){
recuperaImagem = ParseQuery.getQuery("Imagem");
// query.whereEqualTo( "username", ParseUser.getCurrentUser().getUsername() );
recuperaImagem.orderByDescending("createdAt");
recuperaImagem.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if ( e == null ){//Sucesso
if ( objects.size() > 0 ){
publicacoes.clear();
for ( ParseObject parseObject : objects ){
publicacoes.add( parseObject );
}
adapter.notifyDataSetChanged();
}
}else{//Erro
e.printStackTrace();
}
}
});
}
First you have to capture the name of the product. From what I see you take the image there in Parsequery,getQuery("Image"). Likewise, can you get the name of the product? That would be the first step.
– viana
thanks for the reply,thought about it tbm but the doubt would be how to assemble the lines of code
– Felipe Moreira
I know how to do it, what I don’t know is where do you get the other information in the picture. No one answered yet because more information is missing in your question.
– viana
no other information man, I just pull the image
– Felipe Moreira
You pull the image from where man?
– viana
pull from parse database
– Felipe Moreira
a guy told me that in the database I could create another column beyond the image that would be the description, so I would pull the description equal pull the image, but I tried and it didn’t work, I must be writing the wrong code.... you could give me a light?
– Felipe Moreira
Yes, if there is no description in the bank, you have to create, and pull in this same way as you are doing with the image. Is this database external or internal? Check where the table was created and add the column 'Description'... It is difficult to help you not having enough information man, because listing image and text is very simple, but we need to return the description first and then list it.
– viana
The bank is external, called parse, if you can tell me what you need to help me
– Felipe Moreira